Store the numparam dicoS structure for each circuit in a list.

Functions to add, remove, retrive dicoS from the list and to
update dicoS, if the circuit has been changed.
Keeping dicoS is necessary because it may be used by measure.
This patch prevents (huge) memory leaks by overwriting dicoS
if multiple calls to the 'source' command are executed.
This commit is contained in:
h_vogt 2016-06-12 00:03:26 +02:00 committed by rlar
parent c6eb18aef8
commit 06adfa3753
6 changed files with 46 additions and 0 deletions

View File

@ -1044,6 +1044,7 @@ inp_dodeck(
ct->ci_inprogress = FALSE;
ct->ci_runonce = FALSE;
ct->ci_commands = end;
ct->ci_dicos = nupa_add_dicoslist();
if (reuse)
tfree(ct->ci_filename);
ct->ci_filename = copy(filename);

View File

@ -21,6 +21,9 @@ 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 nupa_add_dicoslist(void);
extern void nupa_rem_dicoslist(int);
extern void nupa_set_dicoslist(int);
extern int dynMaxckt; /* number of lines in deck after expansion */

View File

@ -409,6 +409,7 @@ static unsigned char dologfileS = 0; /* for debugging */
static unsigned char firstsignalS = 1;
static FILE *logfileS = NULL;
static dico_t *dicoS = NULL;
static dico_t *dicos_list[100];
/* already part of dico : */
@ -909,3 +910,36 @@ dump_symbols(dico_t *dico)
fprintf(stderr, "Symbol table\n");
nupa_list_params(stderr);
}
/* Store dicoS for each circuit loaded.
The return value will be stored in ft_curckt->ci_dicos.
We need to keep dicoS because it may be used by measure. */
int
nupa_add_dicoslist(void)
{
int i;
for (i = 0; i < 100; i++)
if (dicos_list[i] == NULL) {
dicos_list[i] = dicoS;
break;
}
return (i);
}
/* remove dicoS from list if circuit is removed */
void
nupa_rem_dicoslist(int ir)
{
dicos_list[ir] = NULL;
}
/* change dicoS to the active circuit */
void
nupa_set_dicoslist(int ir)
{
dicoS = dicos_list[ir];
}

View File

@ -15,6 +15,8 @@ Modified: 2000 AlansFixes
#include "ngspice/ftedebug.h"
#include "ngspice/dvec.h"
#include "numparam/numpaif.h"
#include "circuits.h"
#include "completion.h"
#include "runcoms.h"
@ -108,6 +110,8 @@ com_scirc(wordlist *wl)
modtab = ft_curckt->ci_modtab;
/* get the database for save, iplot, stop */
dbs = ft_curckt->ci_dbs;
/* set the numparam dicos structure for use with measure */
nupa_set_dicoslist(ft_curckt->ci_dicos);
}

View File

@ -222,6 +222,8 @@ com_remcirc(wordlist *wl)
/* delete numparam data structure dicoS */
nupa_del_dicoS();
/* delete entry in dicoslist */
nupa_rem_dicoslist(ft_curckt->ci_dicos);
dbfree(ft_curckt->ci_dbs);
ft_curckt->ci_dbs = NULL;
@ -281,5 +283,6 @@ com_remcirc(wordlist *wl)
if (ft_curckt) {
modtab = ft_curckt->ci_modtab;
dbs = ft_curckt->ci_dbs;
nupa_set_dicoslist(ft_curckt->ci_dicos);
}
}

View File

@ -53,6 +53,7 @@ struct circ {
JOB *ci_specOpt; /* the special options anal. for command line jobs */
JOB *ci_curOpt; /* the most recent options anal. for the circuit */
char *ci_last_an; /* name of last analysis run */
int ci_dicos; /* index to the numparam dicoS structure for this circuit*/
FTESTATistics *FTEstats; /* Statistics for the front end */
} ;