From efbb7badbc682359feed293b418169827f64aec2 Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 3 Feb 2018 22:16:49 +0100 Subject: [PATCH] extend commit: spicelib/devcies/*dest.c, rewrite DEVdestroy() functions rewrite admst/ngspiceMODULEdest.c.xml too, see commit > commit 4d79617cf1fd9824d57d62371d2bfee0503f9202 > Date: Fri Jul 29 22:22:16 2016 +0200 > > spicelib/devcies/*dest.c, rewrite DEVdestroy() functions --- .../adms/admst/ngspiceMODULEdest.c.xml | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEdest.c.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEdest.c.xml index 341560499..e15c38ddc 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMODULEdest.c.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEdest.c.xml @@ -40,35 +40,29 @@ - #include "ngspice/ngspice.h" #include "$(module)defs.h" #include "ngspice/suffix.h" -void $(module)destroy(GENmodel **inModel) - +void +$(module)destroy(GENmodel **inModel) { - register $(module)model **model = ($(module)model**)inModel; - register $(module)instance *here; - $(module)instance *prev = NULL; - $(module)model *mod = *model; - $(module)model *oldmod = NULL; - - for ( ; mod ; mod = mod->$(module)nextModel ) { - if (oldmod) FREE(oldmod); - oldmod = mod; - prev = ($(module)instance *)NULL; - for (here = mod->$(module)instances; here ; here = here->$(module)nextInstance) { - if(prev) FREE(prev); - prev = here; - } - if(prev) FREE(prev); - } - if(oldmod) FREE(oldmod); - *model = NULL; - return; -} + $(module)model *mod = *($(module)model**) inModel; + while (mod) { + $(module)model *next_mod = mod->$(module)nextModel; + $(module)instance *inst = mod->$(module)instances; + while (inst) { + $(module)instance *next_inst = inst->$(module)nextInstance; + FREE(inst); + inst = next_inst; + } + FREE(mod); + mod = next_mod; + } + + *inModel = NULL; +}