From e9d957d2d6c7ef65f1cb377a688cfbefacd564ef Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sun, 29 Mar 2009 16:58:44 +0000 Subject: [PATCH] memory leaks removed --- ChangeLog | 3 +++ src/frontend/inp.c | 12 +++++++----- src/frontend/variable.c | 25 +++++++++++++++++++++---- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6185fab7c..b47eec351 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2009-03-29 Holger Vogt + * inp.c, variable.c: some more memory leaks removed + 2009-03-27 Holger Vogt * inpcom.c, variable.c, cpitf.c: memory leaks removed, which were detected by valgrind-3.4.1 under SUSE 11.1 diff --git a/src/frontend/inp.c b/src/frontend/inp.c index cbfda7ccb..4dd302c89 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -349,12 +349,11 @@ inp_spsource(FILE *fp, bool comfile, char *filename) return; } - if (!comfile) + if (!comfile) { options = inp_getopts(deck); - realdeck = inp_deckcopy(deck); + realdeck = inp_deckcopy(deck); - if (!comfile) { /* Save the title before INPgetTitle gets it. */ tt = copy(deck->li_line); if (!deck->li_next) @@ -394,8 +393,8 @@ inp_spsource(FILE *fp, bool comfile, char *filename) else cp_evloop(dd->li_line); } - line_free(dd,FALSE); /* SJB - free this line's memory */ - } + } + line_free(deck,TRUE); } /* end if(comfile) */ else { /* must be regular deck . . . . */ @@ -615,6 +614,8 @@ inp_spsource(FILE *fp, bool comfile, char *filename) } #endif + line_free(deck, TRUE); + /* Now that the deck is loaded, do the commands, if there are any */ if (controls) { for (end = wl = wl_reverse(controls); wl; wl = wl->wl_next) @@ -638,6 +639,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename) cp_curin = lastin; cp_curout = lastout; cp_curerr = lasterr; + return; } diff --git a/src/frontend/variable.c b/src/frontend/variable.c index a0923c730..1377fcbd7 100644 --- a/src/frontend/variable.c +++ b/src/frontend/variable.c @@ -89,7 +89,7 @@ cp_vset(char *varname, char type, char *value) { struct variable *v, *u, *w; int i; - bool alreadythere = FALSE; + bool alreadythere = FALSE, v_free = FALSE; char* copyvarname; @@ -109,11 +109,16 @@ cp_vset(char *varname, char type, char *value) v = alloc(struct variable); v->va_name = copy(copyvarname); v->va_next = NULL; + v_free = TRUE; } switch (type) { case VT_BOOL: if (* ((bool *) value) == FALSE) { cp_remvar(copyvarname); + if(v_free) { + tfree(v->va_name); + tfree(v); + } return; } else v->va_bool = TRUE; @@ -238,7 +243,8 @@ cp_vset(char *varname, char type, char *value) case US_NOSIMVAR: /* What do you do? */ - tfree(v); + tfree(v->va_name); + tfree(v); break; @@ -502,7 +508,7 @@ cp_remvar(char *varname) fprintf(cp_err, "cp_remvar: Internal Error: US val %d\n", i); break; } - + tfree(v->va_name); tfree(v); return; } @@ -679,6 +685,7 @@ cp_variablesubst(wordlist *wlist) (void) strcpy(tbuf, t); /* MW. Save t*/ if (!(wl = wl_splice(wl, nwl))) /*CDHW this frees wl CDHW*/ return (NULL); + /* This is bad... */ for (wlist = wl; wlist->wl_prev; wlist = wlist->wl_prev) ; @@ -692,8 +699,10 @@ cp_variablesubst(wordlist *wlist) s = wl->wl_word; for (i = 0; s < t; s++) wbuf[i++] = *s; + } } + return (wlist); } @@ -725,6 +734,7 @@ vareval(char *string) (void) sprintf(buf, "%d", getpid()); wl->wl_word = copy(buf); + tfree(oldstring); return (wl); case '<': @@ -740,6 +750,7 @@ vareval(char *string) /* This is a hack. */ if (!wl->wl_word) wl->wl_word = copy(""); + tfree(oldstring); return (wl); case '?': @@ -752,6 +763,7 @@ vareval(char *string) if (!v) v = cp_enqvar(string); wl->wl_word = copy(v ? "1" : "0"); + tfree(oldstring); return (wl); case '#': @@ -766,6 +778,7 @@ vareval(char *string) if (!v) { fprintf(cp_err, "Error: %s: no such variable.\n", string); + tfree(oldstring); return (NULL); } if (v->va_type == VT_LIST) @@ -775,12 +788,14 @@ vareval(char *string) i = (v->va_type != VT_BOOL); (void) sprintf(buf, "%d", i); wl->wl_word = copy(buf); + tfree(oldstring); return (wl); case '\0': wl = alloc(struct wordlist); wl->wl_next = wl->wl_prev = NULL; wl->wl_word = copy("$"); + tfree(oldstring); return (wl); } @@ -806,10 +821,12 @@ vareval(char *string) wl = alloc(struct wordlist); wl->wl_next = wl->wl_prev = NULL; wl->wl_word = copy(s); + tfree(oldstring); return (wl); } if (!v) { fprintf(cp_err, "Error: %s: no such variable.\n", string); + tfree(oldstring); return (NULL); } wl = cp_varwl(v); @@ -828,7 +845,7 @@ vareval(char *string) up--, low--; wl = wl_range(wl, low, up); } - + tfree(oldstring); return (wl); }