From 127213bff0c528182345db0ded3198b33a574224 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Thu, 29 Dec 2011 19:31:14 +0000 Subject: [PATCH] reduce memory leaks for run - reset --- ChangeLog | 5 +++ src/spicelib/devices/bsim4v6/b4v6dest.c | 52 +++++++++++++++++-------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index bbcbd8acd..e683410b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-12-29 Holger Vogt + * b4v6dest.c : improved removal of circuit installation, + bug no. 3229770. Memory leaks are quasi gone for + 10 run - reset sequences of a 1000 transistor circuit + 2011-12-29 Robert Larice * src/include/ngspice/Makefile.am : install headers in $(pkdatadir)/include/ngspice diff --git a/src/spicelib/devices/bsim4v6/b4v6dest.c b/src/spicelib/devices/bsim4v6/b4v6dest.c index caa91e182..57dc4227b 100644 --- a/src/spicelib/devices/bsim4v6/b4v6dest.c +++ b/src/spicelib/devices/bsim4v6/b4v6dest.c @@ -16,25 +16,45 @@ void BSIM4v6destroy( -GENmodel **inModel) + GENmodel **inModel) { -BSIM4v6model **model = (BSIM4v6model**)inModel; -BSIM4v6instance *here; -BSIM4v6instance *prev = NULL; -BSIM4v6model *mod = *model; -BSIM4v6model *oldmod = NULL; + BSIM4v6model **model = (BSIM4v6model**)inModel; + BSIM4v6instance *here; + BSIM4v6instance *prev = NULL; + BSIM4v6model *mod = *model; + BSIM4v6model *oldmod = NULL; - for (; mod ; mod = mod->BSIM4v6nextModel) - { if(oldmod) FREE(oldmod); - oldmod = mod; - prev = NULL; - for (here = mod->BSIM4v6instances; here; here = here->BSIM4v6nextInstance) - { if(prev) FREE(prev); - prev = here; - } - if(prev) FREE(prev); + for (; mod ; mod = mod->BSIM4v6nextModel) { + /** added to get rid of link list pSizeDependParamKnot **/ + struct bsim4v6SizeDependParam *pParam, *pParamOld=NULL; + + pParam = mod->pSizeDependParamKnot; + + for (; pParam ; pParam = pParam->pNext) { + FREE(pParamOld); + pParamOld = pParam; + } + FREE(pParamOld); + pParam = NULL; + /** end of extra code **/ + + if(oldmod) + FREE(oldmod); + oldmod = mod; + prev = NULL; + for (here = mod->BSIM4v6instances; here; here = here->BSIM4v6nextInstance) { + if(prev) FREE(prev); + prev = here; + } + if(prev) FREE(prev); + } + if(oldmod) { +#ifdef USE_OMP4 + /* free just once for all models */ + FREE(oldmod->BSIM4v6InstanceArray); +#endif + FREE(oldmod); } - if(oldmod) FREE(oldmod); *model = NULL; return; }