From da10f497558ac6e89078a476e6255b8562968356 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Mon, 19 Aug 2013 20:30:48 +0200 Subject: [PATCH] remove memory leak freeing dicoS reported by Jonathan Knott --- src/frontend/inp.c | 5 ++++ src/frontend/measure.c | 3 +++ src/frontend/numparam/numpaif.h | 1 + src/frontend/numparam/spicenum.c | 39 +++++++++++++++++++------------- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 717b059bf..cff7441ca 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -634,6 +634,11 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) prev_card = dd; } //end of for-loop + /* If we don't have .meas lines, we free the dicoS structure now. + If we have .meas lines, dicoS is freed in do_measure() */ + if (ft_curckt && !ft_curckt->ci_meas) + nupa_del_dicoS(); + /* set temperature, if defined, to new value. cp_vset will set the variable "temp" and also set CKTtemp, so we can do it only here because the circuit has to be already there */ diff --git a/src/frontend/measure.c b/src/frontend/measure.c index 546bf92d3..925f40e96 100644 --- a/src/frontend/measure.c +++ b/src/frontend/measure.c @@ -431,6 +431,9 @@ do_measure( txfree(an_name); + /* numparam data structure dicoS is no longer needed */ + nupa_del_dicoS(); + fflush(stdout); return(measures_passed); diff --git a/src/frontend/numparam/numpaif.h b/src/frontend/numparam/numpaif.h index 51b1477e6..706034368 100644 --- a/src/frontend/numparam/numpaif.h +++ b/src/frontend/numparam/numpaif.h @@ -20,6 +20,7 @@ extern double nupa_get_param(char *param_name, int *found); extern void nupa_add_param(char *param_name, double value); extern void nupa_add_inst_param(char *param_name, double value); extern void nupa_copy_inst_dico(void); +extern void nupa_del_dicoS(void); extern int dynMaxckt; /* number of lines in deck after expansion */ diff --git a/src/frontend/numparam/spicenum.c b/src/frontend/numparam/spicenum.c index 4b98d5062..8dd24e2d4 100644 --- a/src/frontend/numparam/spicenum.c +++ b/src/frontend/numparam/spicenum.c @@ -472,6 +472,26 @@ nupa_init(char *srcfile) } +/* free dicoS (called from do_measure() in measure.c or + immediately from inp_spsource() in inp.c) */ +void +nupa_del_dicoS(void) +{ + int i; + + if(!dicoS) + return; + + for (i = dynmaxline; i >= 0; i--) + dispose(dicoS->dynrefptr[i]); + + dispose(dicoS->dynrefptr); + dispose(dicoS->dyncategory); + dispose(dicoS); + dicoS = NULL; +} + + static void nupa_done(void) { @@ -490,22 +510,9 @@ nupa_done(void) nerrors = dicoS->errcount; dictsize = donedico(dicoS); - /* We cannot remove dico here because numparam is usedby - the .measure statement, which is invoked only after the - simulation has finished */ - /* - * for (i = dynmaxline; i >= 0; i--) { - * dispose(dico->dynrefptr[i]); - * } - * dispose(dico->dynrefptr); - * dispose(dico->dyncategory); - * dispose(dico->dyndat); - * dispose(dico); - * dico = NULL; - * dispose(inst_dico->dyndat); - * dispose(inst_dico); - * inst_dico = NULL; - */ + /* We cannot remove dicoS here because numparam is used by + the .measure statements, which are invoked only after the + simulation has finished. */ if (nerrors) { /* debug: ask if spice run really wanted */