Modified Files:

Tag: TCLSPICE
 	ChangeLog src/frontend/com_let.c
 	src/frontend/com_set.c src/frontend/evaluate.c
 	src/frontend/parse.c src/frontend/variable.c
 	src/frontend/parser/complete.c

	Plug memory leaks
This commit is contained in:
stefanjones 2003-07-15 12:16:25 +00:00
parent 3a100bdc64
commit b9377782d3
7 changed files with 39 additions and 7 deletions

View File

@ -1,3 +1,9 @@
2003-07-15 Stefan Jones <stefan.jones@multigig.com>
* /src/frontend/{com_let.c,com_set.c,evaluate.c,parse.c,variable.c}
src/frontend/parser/complete.c :
Memory leaks plugged
2003-07-14 Stefan Jones <stefan.jones@multigig.com> 2003-07-14 Stefan Jones <stefan.jones@multigig.com>
* src/include/enh.h src/spicelib/analysis/{acan.c,cktload.c,cktsetup.c,cktsopt.c} * src/include/enh.h src/spicelib/analysis/{acan.c,cktload.c,cktsetup.c,cktsopt.c}

View File

@ -101,6 +101,7 @@ com_let(wordlist *wl)
if (!t) { if (!t) {
fprintf(cp_err, "Error: Can't evaluate %s\n", rhs); fprintf(cp_err, "Error: Can't evaluate %s\n", rhs);
tfree(p); tfree(p);
free_pnode(nn);
return; return;
} }
@ -117,6 +118,7 @@ com_let(wordlist *wl)
if (numdims) { if (numdims) {
fprintf(cp_err, "Can't assign into a subindex of a new vector\n"); fprintf(cp_err, "Can't assign into a subindex of a new vector\n");
tfree(p); tfree(p);
free_pnode(nn);
return; return;
} }
@ -176,6 +178,7 @@ com_let(wordlist *wl)
if (newvec) if (newvec)
n->v_flags &= ~VF_PERMANENT; n->v_flags &= ~VF_PERMANENT;
tfree(p); tfree(p);
free_pnode(nn);
return; return;
} }
if (isreal(t) != isreal(n)) { if (isreal(t) != isreal(n)) {
@ -184,6 +187,7 @@ com_let(wordlist *wl)
if (newvec) if (newvec)
n->v_flags &= ~VF_PERMANENT; n->v_flags &= ~VF_PERMANENT;
tfree(p); tfree(p);
free_pnode(nn);
return; return;
} else if (isreal(t)) { } else if (isreal(t)) {
bcopy((char *) t->v_realdata, (char *) (n->v_realdata + offset), bcopy((char *) t->v_realdata, (char *) (n->v_realdata + offset),
@ -201,7 +205,7 @@ com_let(wordlist *wl)
if (newvec) if (newvec)
cp_addkword(CT_VECTOR, n->v_name); cp_addkword(CT_VECTOR, n->v_name);
/* XXXX Free t !?! */
tfree(p); tfree(p);
free_pnode(nn);
return; return;
} }

View File

@ -13,7 +13,7 @@
void void
com_set(wordlist *wl) com_set(wordlist *wl)
{ {
struct variable *vars; struct variable *vars, *tmp;
char *s; char *s;
if (wl == NULL) { if (wl == NULL) {
@ -44,8 +44,14 @@ com_set(wordlist *wl)
s = (char *) NULL; s = (char *) NULL;
} }
cp_vset(vars->va_name, vars->va_type, s); cp_vset(vars->va_name, vars->va_type, s);
if(vars->va_type == VT_STRING)
tfree(s);
tfree(vars->va_name);
tmp = vars;
vars = vars->va_next; vars = vars->va_next;
tfree(tmp);
} }
return; return;
} }

View File

@ -67,8 +67,11 @@ ft_evaluate(struct pnode *node)
return NULL; return NULL;
} }
if (node->pn_name && !ft_evdb && d && !d->v_link2) if (node->pn_name && !ft_evdb && d && !d->v_link2) {
if(d->v_name)
tfree(d->v_name);
d->v_name = copy(node->pn_name); d->v_name = copy(node->pn_name);
}
if (!d->v_length) { if (!d->v_length) {
fprintf(cp_err, "Error: no such vector %s\n", d->v_name); fprintf(cp_err, "Error: no such vector %s\n", d->v_name);

View File

@ -405,13 +405,16 @@ static struct pnode *
parse(void) parse(void)
{ {
struct element stack[STACKSIZE]; struct element stack[STACKSIZE];
int sp = 0, st, i; char *stringStack[STACKSIZE];
int sp = 0, st, i, fsp = 0;
struct element *top, *next; struct element *top, *next;
struct pnode *pn, *lpn, *rpn; struct pnode *pn, *lpn, *rpn;
char rel; char rel;
stack[0].e_token = END; stack[0].e_token = END;
next = lexer(); next = lexer();
if(next->e_token == VALUE && next->e_type == STRING)
stringStack[fsp++] = next->e_string;
while ((sp > 1) || (next->e_token != END)) { while ((sp > 1) || (next->e_token != END)) {
/* Find the top-most terminal. */ /* Find the top-most terminal. */
@ -424,13 +427,15 @@ parse(void)
case L: case L:
case E: case E:
/* Push the token read. */ /* Push the token read. */
if (sp == (STACKSIZE - 1)) { if (sp == (STACKSIZE - 1) || fsp == (STACKSIZE-1)) {
fprintf(cp_err, "Error: stack overflow\n"); fprintf(cp_err, "Error: stack overflow\n");
return (NULL); return (NULL);
} }
bcopy((char *) next, (char *) &stack[++sp], bcopy((char *) next, (char *) &stack[++sp],
sizeof (struct element)); sizeof (struct element));
next = lexer(); next = lexer();
if(next->e_token == VALUE && next->e_type == STRING)
stringStack[fsp++] = next->e_string;
continue; continue;
case R: case R:
@ -506,6 +511,8 @@ parse(void)
} }
} }
pn = makepnode(&stack[1]); pn = makepnode(&stack[1]);
for(i=0;i<fsp;i++)
tfree(stringStack[i]);
if (pn) if (pn)
return (pn); return (pn);
err: err:
@ -815,6 +822,9 @@ free_pnode(struct pnode *t)
free_pnode(t->pn_left); free_pnode(t->pn_left);
free_pnode(t->pn_right); free_pnode(t->pn_right);
free_pnode(t->pn_next); free_pnode(t->pn_next);
tfree(t->pn_name);
if(t->pn_value)
vec_free(t->pn_value);
tfree(t); tfree(t);
} }

View File

@ -518,7 +518,6 @@ cp_addkword(int class, char *word)
class); class);
return; return;
} }
word = copy(word);
cc = clookup(word, &keywords[class], FALSE, TRUE); cc = clookup(word, &keywords[class], FALSE, TRUE);
cc->cc_invalid = 0; cc->cc_invalid = 0;
return; return;

View File

@ -238,13 +238,15 @@ cp_vset(char *varname, char type, char *value)
struct variable * struct variable *
cp_setparse(wordlist *wl) cp_setparse(wordlist *wl)
{ {
char *name, *val, *copyval, *s, *ss; char *name=NULL, *val, *copyval, *s, *ss;
double *td; double *td;
struct variable *listv = NULL, *vv, *lv = NULL; struct variable *listv = NULL, *vv, *lv = NULL;
struct variable *vars = NULL; struct variable *vars = NULL;
int balance; int balance;
while (wl) { while (wl) {
if(name)
tfree(name);
name = cp_unquote(wl->wl_word); name = cp_unquote(wl->wl_word);
wl = wl->wl_next; wl = wl->wl_next;
if (((wl == NULL) || (*wl->wl_word != '=')) && if (((wl == NULL) || (*wl->wl_word != '=')) &&
@ -357,6 +359,8 @@ cp_setparse(wordlist *wl)
} }
tfree(copyval);/*DG: must free ss any way to avoid cp_unquote memory leak */ tfree(copyval);/*DG: must free ss any way to avoid cp_unquote memory leak */
} }
if(name)
tfree(name);
return (vars); return (vars);
} }