From 041264df030df9c0004a619705381a3b9b7aaaaf Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Tue, 13 Jul 2021 17:12:11 +0200 Subject: [PATCH] No more meory leaks with existing cpl examples: Add cpldelete.c and cplmdel.c Delete the model parameters. Add 2 missing memsaved(). --- src/spicelib/devices/cpl/Makefile.am | 3 +++ src/spicelib/devices/cpl/cpldelete.c | 21 +++++++++++++++++++++ src/spicelib/devices/cpl/cplext.h | 2 ++ src/spicelib/devices/cpl/cplinit.c | 4 ++-- src/spicelib/devices/cpl/cplmdel.c | 24 ++++++++++++++++++++++++ src/spicelib/devices/cpl/cplmpar.c | 2 -- src/spicelib/devices/cpl/cplsetup.c | 4 +++- visualc/vngspice.vcxproj | 2 ++ 8 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 src/spicelib/devices/cpl/cpldelete.c create mode 100644 src/spicelib/devices/cpl/cplmdel.c diff --git a/src/spicelib/devices/cpl/Makefile.am b/src/spicelib/devices/cpl/Makefile.am index a3da8a735..9cbd00a18 100644 --- a/src/spicelib/devices/cpl/Makefile.am +++ b/src/spicelib/devices/cpl/Makefile.am @@ -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 diff --git a/src/spicelib/devices/cpl/cpldelete.c b/src/spicelib/devices/cpl/cpldelete.c new file mode 100644 index 000000000..5159a7d70 --- /dev/null +++ b/src/spicelib/devices/cpl/cpldelete.c @@ -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; +} diff --git a/src/spicelib/devices/cpl/cplext.h b/src/spicelib/devices/cpl/cplext.h index 2225084aa..4c28a93a6 100644 --- a/src/spicelib/devices/cpl/cplext.h +++ b/src/spicelib/devices/cpl/cplext.h @@ -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*); diff --git a/src/spicelib/devices/cpl/cplinit.c b/src/spicelib/devices/cpl/cplinit.c index b6a9aff7c..4386a939b 100644 --- a/src/spicelib/devices/cpl/cplinit.c +++ b/src/spicelib/devices/cpl/cplinit.c @@ -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, diff --git a/src/spicelib/devices/cpl/cplmdel.c b/src/spicelib/devices/cpl/cplmdel.c new file mode 100644 index 000000000..5f493ec55 --- /dev/null +++ b/src/spicelib/devices/cpl/cplmdel.c @@ -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; +} diff --git a/src/spicelib/devices/cpl/cplmpar.c b/src/spicelib/devices/cpl/cplmpar.c index 693bd5a7d..eea37b6bb 100644 --- a/src/spicelib/devices/cpl/cplmpar.c +++ b/src/spicelib/devices/cpl/cplmpar.c @@ -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)); } diff --git a/src/spicelib/devices/cpl/cplsetup.c b/src/spicelib/devices/cpl/cplsetup.c index 82e06bea7..7584269f7 100644 --- a/src/spicelib/devices/cpl/cplsetup.c +++ b/src/spicelib/devices/cpl/cplsetup.c @@ -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) { diff --git a/visualc/vngspice.vcxproj b/visualc/vngspice.vcxproj index f6d2c27fb..9c37b349e 100644 --- a/visualc/vngspice.vcxproj +++ b/visualc/vngspice.vcxproj @@ -2053,10 +2053,12 @@ + +