No more meory leaks with existing cpl examples:

Add cpldelete.c and cplmdel.c
Delete the model parameters.
Add 2 missing memsaved().
This commit is contained in:
Holger Vogt 2021-07-13 17:12:11 +02:00
parent 9ede9b80e0
commit 041264df03
8 changed files with 57 additions and 5 deletions

View File

@ -14,6 +14,9 @@ libcpl_la_SOURCES = \
cplload.c \
cplmpar.c \
cplsetup.c \
cplhash.c \
cplmdel.c \
cpldelete.c \
cplinit.c
AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/src/include

View File

@ -0,0 +1,21 @@
/**********
Copyright 2021 The ngspice team All rights
reserved.
Author: 2021 Holger Vogt
3-clause BSD license
**********/
#include "ngspice/ngspice.h"
#include "cpldefs.h"
#include "ngspice/sperror.h"
#include "ngspice/suffix.h"
#include "cplhash.h"
int
CPLDelete(GENinstance *gen_inst)
{
NG_IGNORE(gen_inst);
// mem_delete();
return OK;
}

View File

@ -11,3 +11,5 @@ extern int CPLmParam(int,IFvalue*, GENmodel*);
extern int CPLparam(int,IFvalue*, GENinstance*, IFvalue*);
extern int CPLsetup(SMPmatrix*, GENmodel*, CKTcircuit*, int*);
extern int CPLunsetup(GENmodel*, CKTcircuit*);
extern int CPLmDelete(GENmodel*);
extern int CPLDelete(GENinstance*);

View File

@ -43,8 +43,8 @@ SPICEdev CPLinfo = {
.DEVacLoad = NULL,
.DEVaccept = NULL,
.DEVdestroy = NULL,
.DEVmodDelete = NULL,
.DEVdelete = NULL,
.DEVmodDelete = CPLmDelete,
.DEVdelete = CPLDelete,
.DEVsetic = NULL,
.DEVask = CPLask,
.DEVmodAsk = CPLmAsk,

View File

@ -0,0 +1,24 @@
/**********
Copyright 2021 The ngspice team All rights
reserved.
Author: 2021 Holger Vogt
3-clause BSD license
**********/
#include "ngspice/ngspice.h"
#include "cpldefs.h"
#include "ngspice/sperror.h"
#include "ngspice/suffix.h"
int
CPLmDelete(GENmodel *gen_model)
{
CPLmodel *model = (CPLmodel *)gen_model;
FREE(model->Rm);
FREE(model->Lm);
FREE(model->Gm);
FREE(model->Cm);
return OK;
}

View File

@ -19,12 +19,10 @@ static void copy_coeffs(double **dst, IFvalue *value)
int n = value->v.numValue;
if (*dst) {
memdeleted(*dst);
tfree(*dst);
}
*dst = TMALLOC(double, n);
memsaved(*dst);
memcpy(*dst, value->v.vec.rVec, (size_t) n * sizeof(double));
}

View File

@ -374,7 +374,7 @@ CPLunsetup(GENmodel* inModel, CKTcircuit* ckt)
here->CPLibr2Given = 0;
}
}
mem_delete();
// mem_delete();
return OK;
}
@ -1408,6 +1408,7 @@ generate_out(int dim, int deg_o)
}
}
p = SIV[i][j].Poly = (double*)calloc(7, sizeof(double));
memsaved(p);
p[0] = c1;
p[1] = c2;
p[2] = c3;
@ -1540,6 +1541,7 @@ static void matrix_p_mult(
for (k = 0; k < dim; k++) {
p = X[i][j].Poly[k] =
(double*)calloc((size_t)(deg_o + 1), sizeof(double));
memsaved(p);
mult_p(A_in[i][k], T[k][j], p, deg, deg_o, deg_o);
t1 = X[i][j].C_0[k] = p[0];
if (t1 != 0.0) {

View File

@ -2053,10 +2053,12 @@
<ClCompile Include="..\src\spicelib\devices\cktsoachk.c" />
<ClCompile Include="..\src\spicelib\devices\cpl\cpl.c" />
<ClCompile Include="..\src\spicelib\devices\cpl\cplask.c" />
<ClCompile Include="..\src\spicelib\devices\cpl\cpldelete.c" />
<ClCompile Include="..\src\spicelib\devices\cpl\cplhash.c" />
<ClCompile Include="..\src\spicelib\devices\cpl\cplinit.c" />
<ClCompile Include="..\src\spicelib\devices\cpl\cplload.c" />
<ClCompile Include="..\src\spicelib\devices\cpl\cplmask.c" />
<ClCompile Include="..\src\spicelib\devices\cpl\cplmdel.c" />
<ClCompile Include="..\src\spicelib\devices\cpl\cplmpar.c" />
<ClCompile Include="..\src\spicelib\devices\cpl\cplparam.c" />
<ClCompile Include="..\src\spicelib\devices\cpl\cplsetup.c" />