From 2e4b5f71f361df059bc1220da06508f199bd0487 Mon Sep 17 00:00:00 2001 From: pnenzi Date: Mon, 16 Aug 2004 09:10:40 +0000 Subject: [PATCH] Applied vera patch for "show" memleak. --- src/frontend/device.c | 21 ++++++--------------- src/frontend/gens.c | 4 ++++ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/frontend/device.c b/src/frontend/device.c index e4d976be4..cd29ddd5c 100644 --- a/src/frontend/device.c +++ b/src/frontend/device.c @@ -19,11 +19,11 @@ Modified: 2000 AlansFixes #include "device.h" #include "variable.h" +#include "gens.h" /* wl_forall */ static wordlist *devexpand(char *name); static void all_show(wordlist *wl, int mode); - /* * show: list device operating point info * show @@ -38,10 +38,6 @@ static void all_show(wordlist *wl, int mode); static int count; -extern void dgen_nth_next (dgen **dg, int n); -extern int dgen_for_n (dgen *dg, int n, int (*fn) (/* ??? */), char *data, int subindex); -extern void wl_forall (wordlist *wl, int (*fn) (/* ??? */), char *data); - void com_showmod(wordlist *wl) { @@ -60,7 +56,7 @@ all_show(wordlist *wl, int mode) wordlist *params, *nextgroup, *thisgroup; wordlist *prev, *next, *w; int screen_width; - dgen *dg, *listdg = NULL; + dgen *dg, *listdg; int instances; int i, j, n; int param_flag, dev_flag; @@ -197,7 +193,7 @@ all_show(wordlist *wl, int mode) else if (!params) param_forall(dg, DGEN_DEFPARAMS); if (params) - wl_forall(params, (void *)listparam, (void *)dg); + wl_forall(params, listparam, (void *)dg); printf("\n"); } else if (ft_sim->devices[dg->dev_type_no]->numModelParms) { @@ -219,16 +215,11 @@ all_show(wordlist *wl, int mode) else if (!params) param_forall(dg, DGEN_DEFPARAMS); if (params) - wl_forall(params, (void *) listparam, (void *)dg); + wl_forall(params, listparam, (void *)dg); printf("\n"); } } - /* Paolo Nenzi 2004: - * This tfree is necessary to free memory allocated by NEW in - * dgen_init. It is not possible to free dg since it is casted - * to NULL from dgen_next and is lost. - */ - tfree(listdg); + wl = nextgroup; } while (wl); @@ -661,7 +652,7 @@ com_alter_common(wordlist *wl, int do_model) /* va: garbage collection for dv, if pnode names is no simple value */ if (names->pn_value==NULL && dv!=NULL) vec_free(dv); - free_pnode(names); /* free also dv, if pnode names is simple value */ + free_pnode(names); /* free also dv, if pnode names is simple value */ return; } diff --git a/src/frontend/gens.c b/src/frontend/gens.c index aa5400c80..dab0c0a45 100644 --- a/src/frontend/gens.c +++ b/src/frontend/gens.c @@ -82,11 +82,15 @@ void dgen_nth_next(dgen **dg, int n) { int i, dnum; + dgen * dg_old=*dg; + dnum = (*dg)->dev_type_no; for (i = 0; *dg && (*dg)->dev_type_no == dnum && i < n; i++) { dgen_next(dg); + /* va, it might be too much tests, but safer is better... */ + if (*dg!=dg_old && *dg==NULL && dg_old!=NULL) tfree(dg_old); } }