From acfc7a2a2795aaa1266d383680f5e70d30cceaea Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sat, 4 Aug 2012 19:09:13 +0200 Subject: [PATCH] remove memory leaks --- src/frontend/inpcom.c | 5 +++-- src/frontend/plotting/plotit.c | 5 +++++ src/frontend/subckt.c | 2 ++ src/xspice/mif/mif_inp2.c | 12 +++++++++--- src/xspice/mif/mifgetmod.c | 3 +++ src/xspice/mif/mifgetvalue.c | 4 +++- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 5b25a5753..95a526092 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -2996,7 +2996,7 @@ inp_fix_param_values( struct line *deck ) { struct line *c = deck; char *line, *beg_of_str, *end_of_str, *old_str, *equal_ptr, *new_str; - char *vec_str, *natok, *buffer, *newvec, *whereisgt; + char *vec_str, *tmp_str, *natok, *buffer, *newvec, *whereisgt; bool control_section = FALSE; wordlist *nwl; int parens; @@ -3098,7 +3098,7 @@ inp_fix_param_values( struct line *deck ) while (*end_of_str != ']') end_of_str++; /* string xx yyy from vector [xx yyy] */ - vec_str = copy_substring(beg_of_str + 1, end_of_str); + tmp_str = vec_str = copy_substring(beg_of_str + 1, end_of_str); /* work on vector elements inside [] */ nwl = NULL; @@ -3140,6 +3140,7 @@ inp_fix_param_values( struct line *deck ) nwl = wl_cons(copy(buffer), nwl); tfree(buffer); } + tfree(tmp_str); nwl = wl_reverse(nwl); /* new vector elements */ newvec = wl_flatten(nwl); diff --git a/src/frontend/plotting/plotit.c b/src/frontend/plotting/plotit.c index 05ffa69d6..0dc6494b7 100644 --- a/src/frontend/plotting/plotit.c +++ b/src/frontend/plotting/plotit.c @@ -897,6 +897,11 @@ plotit(wordlist *wl, char *hcopy, char *devname) ylims[1] = 1.0; } + if(xlim) + tfree(xlim); + if(ylim) + tfree(ylim); + /* We don't want to try to deal with smith plots for asciiplot. */ if (devname && eq(devname, "lpr")) { /* check if we should (can) linearize */ diff --git a/src/frontend/subckt.c b/src/frontend/subckt.c index ac68f20c0..84ee7eed4 100644 --- a/src/frontend/subckt.c +++ b/src/frontend/subckt.c @@ -978,6 +978,8 @@ translate(struct line *deck, char *formal, char *actual, char *scname, char *sub for (;;) { /* rotate the tokens and get the the next one */ + if (name) + tfree(name); name = next_name; next_name = MIFgettok(&s); diff --git a/src/xspice/mif/mif_inp2.c b/src/xspice/mif/mif_inp2.c index c95e254b6..13cf419da 100644 --- a/src/xspice/mif/mif_inp2.c +++ b/src/xspice/mif/mif_inp2.c @@ -163,6 +163,7 @@ card *current ) /* the card we are to parse */ char *def_port_type_str; /* The default port type in string form */ char *next_token; /* a token string */ + char *tmp_token; /* a token string */ int i; /* a loop counter */ int j; /* a loop counter */ @@ -195,8 +196,11 @@ card *current ) /* the card we are to parse */ INPinsert(&name, tab); /* locate the last token on the line (i.e. model name) and put it into "model" */ - while(*line != '\0') + while(*line != '\0') { + if (model) + tfree(model); model = MIFgettok(&line); + } /* make sure the model name was there. */ if(model == NULL) { @@ -212,7 +216,6 @@ card *current ) /* the card we are to parse */ return; } - /* get the integer index into the DEVices data array for this */ /* model */ type = thismodel->INPmodType; @@ -237,7 +240,8 @@ card *current ) /* the card we are to parse */ /* reset 'line', and then read instance name again. */ line = current->line; - MIFgettok(&line); /* read instance name again . . . .*/ + tmp_token = MIFgettok(&line); /* read instance name again . . . .*/ + tfree(tmp_token); /* OK -- now &line points to the first token after the instance name and we are ready to process the connections @@ -469,6 +473,8 @@ card *current ) /* the card we are to parse */ return; } + tfree(model); + /* check connection constraints */ for(i = 0; i < DEVices[type]->DEVpublic.num_conn; i++) { diff --git a/src/xspice/mif/mifgetmod.c b/src/xspice/mif/mifgetmod.c index 4ebca0396..a5f1dcca1 100644 --- a/src/xspice/mif/mifgetmod.c +++ b/src/xspice/mif/mifgetmod.c @@ -181,11 +181,14 @@ char *MIFgetMod( /* parameter isolation, identification, binding */ line = modtmp->INPmodLine->line; INPgetTok(&line,&parm,1); /* throw away '.model' */ + tfree(parm); INPgetTok(&line,&parm,1); /* throw away 'modname' */ + tfree(parm); /* throw away the modtype - we don't treat it as a parameter */ /* like SPICE does */ INPgetTok(&line,&parm,1); /* throw away 'modtype' */ + tfree(parm); while(*line != 0) { INPgetTok(&line,&parm,1); diff --git a/src/xspice/mif/mifgetvalue.c b/src/xspice/mif/mifgetvalue.c index 9dd4f91c4..02d9669d9 100644 --- a/src/xspice/mif/mifgetvalue.c +++ b/src/xspice/mif/mifgetvalue.c @@ -220,9 +220,11 @@ MIFgetValue ( if(! is_array) break; - } /* end forever loop */ + tfree(token); + } /* end forever loop */ + tfree(token); return(&val); }