Browse Source

memory leaks removed

pre-master-46
h_vogt 17 years ago
parent
commit
e9d957d2d6
  1. 3
      ChangeLog
  2. 12
      src/frontend/inp.c
  3. 25
      src/frontend/variable.c

3
ChangeLog

@ -1,3 +1,6 @@
2009-03-29 Holger Vogt
* inp.c, variable.c: some more memory leaks removed
2009-03-27 Holger Vogt 2009-03-27 Holger Vogt
* inpcom.c, variable.c, cpitf.c: memory leaks removed, which were detected by * inpcom.c, variable.c, cpitf.c: memory leaks removed, which were detected by
valgrind-3.4.1 under SUSE 11.1 valgrind-3.4.1 under SUSE 11.1

12
src/frontend/inp.c

@ -349,12 +349,11 @@ inp_spsource(FILE *fp, bool comfile, char *filename)
return; return;
} }
if (!comfile)
if (!comfile) {
options = inp_getopts(deck); options = inp_getopts(deck);
realdeck = inp_deckcopy(deck);
realdeck = inp_deckcopy(deck);
if (!comfile) {
/* Save the title before INPgetTitle gets it. */ /* Save the title before INPgetTitle gets it. */
tt = copy(deck->li_line); tt = copy(deck->li_line);
if (!deck->li_next) if (!deck->li_next)
@ -394,8 +393,8 @@ inp_spsource(FILE *fp, bool comfile, char *filename)
else else
cp_evloop(dd->li_line); cp_evloop(dd->li_line);
} }
line_free(dd,FALSE); /* SJB - free this line's memory */
}
}
line_free(deck,TRUE);
} /* end if(comfile) */ } /* end if(comfile) */
else { /* must be regular deck . . . . */ else { /* must be regular deck . . . . */
@ -615,6 +614,8 @@ inp_spsource(FILE *fp, bool comfile, char *filename)
} }
#endif #endif
line_free(deck, TRUE);
/* Now that the deck is loaded, do the commands, if there are any */ /* Now that the deck is loaded, do the commands, if there are any */
if (controls) { if (controls) {
for (end = wl = wl_reverse(controls); wl; wl = wl->wl_next) 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_curin = lastin;
cp_curout = lastout; cp_curout = lastout;
cp_curerr = lasterr; cp_curerr = lasterr;
return; return;
} }

25
src/frontend/variable.c

@ -89,7 +89,7 @@ cp_vset(char *varname, char type, char *value)
{ {
struct variable *v, *u, *w; struct variable *v, *u, *w;
int i; int i;
bool alreadythere = FALSE;
bool alreadythere = FALSE, v_free = FALSE;
char* copyvarname; char* copyvarname;
@ -109,11 +109,16 @@ cp_vset(char *varname, char type, char *value)
v = alloc(struct variable); v = alloc(struct variable);
v->va_name = copy(copyvarname); v->va_name = copy(copyvarname);
v->va_next = NULL; v->va_next = NULL;
v_free = TRUE;
} }
switch (type) { switch (type) {
case VT_BOOL: case VT_BOOL:
if (* ((bool *) value) == FALSE) { if (* ((bool *) value) == FALSE) {
cp_remvar(copyvarname); cp_remvar(copyvarname);
if(v_free) {
tfree(v->va_name);
tfree(v);
}
return; return;
} else } else
v->va_bool = TRUE; v->va_bool = TRUE;
@ -238,7 +243,8 @@ cp_vset(char *varname, char type, char *value)
case US_NOSIMVAR: case US_NOSIMVAR:
/* What do you do? */ /* What do you do? */
tfree(v);
tfree(v->va_name);
tfree(v);
break; break;
@ -502,7 +508,7 @@ cp_remvar(char *varname)
fprintf(cp_err, "cp_remvar: Internal Error: US val %d\n", i); fprintf(cp_err, "cp_remvar: Internal Error: US val %d\n", i);
break; break;
} }
tfree(v->va_name);
tfree(v); tfree(v);
return; return;
} }
@ -679,6 +685,7 @@ cp_variablesubst(wordlist *wlist)
(void) strcpy(tbuf, t); /* MW. Save t*/ (void) strcpy(tbuf, t); /* MW. Save t*/
if (!(wl = wl_splice(wl, nwl))) /*CDHW this frees wl CDHW*/ if (!(wl = wl_splice(wl, nwl))) /*CDHW this frees wl CDHW*/
return (NULL); return (NULL);
/* This is bad... */ /* This is bad... */
for (wlist = wl; wlist->wl_prev; wlist = wlist->wl_prev) for (wlist = wl; wlist->wl_prev; wlist = wlist->wl_prev)
; ;
@ -692,8 +699,10 @@ cp_variablesubst(wordlist *wlist)
s = wl->wl_word; s = wl->wl_word;
for (i = 0; s < t; s++) for (i = 0; s < t; s++)
wbuf[i++] = *s; wbuf[i++] = *s;
} }
} }
return (wlist); return (wlist);
} }
@ -725,6 +734,7 @@ vareval(char *string)
(void) sprintf(buf, "%d", getpid()); (void) sprintf(buf, "%d", getpid());
wl->wl_word = copy(buf); wl->wl_word = copy(buf);
tfree(oldstring);
return (wl); return (wl);
case '<': case '<':
@ -740,6 +750,7 @@ vareval(char *string)
/* This is a hack. */ /* This is a hack. */
if (!wl->wl_word) if (!wl->wl_word)
wl->wl_word = copy(""); wl->wl_word = copy("");
tfree(oldstring);
return (wl); return (wl);
case '?': case '?':
@ -752,6 +763,7 @@ vareval(char *string)
if (!v) if (!v)
v = cp_enqvar(string); v = cp_enqvar(string);
wl->wl_word = copy(v ? "1" : "0"); wl->wl_word = copy(v ? "1" : "0");
tfree(oldstring);
return (wl); return (wl);
case '#': case '#':
@ -766,6 +778,7 @@ vareval(char *string)
if (!v) { if (!v) {
fprintf(cp_err, "Error: %s: no such variable.\n", fprintf(cp_err, "Error: %s: no such variable.\n",
string); string);
tfree(oldstring);
return (NULL); return (NULL);
} }
if (v->va_type == VT_LIST) if (v->va_type == VT_LIST)
@ -775,12 +788,14 @@ vareval(char *string)
i = (v->va_type != VT_BOOL); i = (v->va_type != VT_BOOL);
(void) sprintf(buf, "%d", i); (void) sprintf(buf, "%d", i);
wl->wl_word = copy(buf); wl->wl_word = copy(buf);
tfree(oldstring);
return (wl); return (wl);
case '\0': case '\0':
wl = alloc(struct wordlist); wl = alloc(struct wordlist);
wl->wl_next = wl->wl_prev = NULL; wl->wl_next = wl->wl_prev = NULL;
wl->wl_word = copy("$"); wl->wl_word = copy("$");
tfree(oldstring);
return (wl); return (wl);
} }
@ -806,10 +821,12 @@ vareval(char *string)
wl = alloc(struct wordlist); wl = alloc(struct wordlist);
wl->wl_next = wl->wl_prev = NULL; wl->wl_next = wl->wl_prev = NULL;
wl->wl_word = copy(s); wl->wl_word = copy(s);
tfree(oldstring);
return (wl); return (wl);
} }
if (!v) { if (!v) {
fprintf(cp_err, "Error: %s: no such variable.\n", string); fprintf(cp_err, "Error: %s: no such variable.\n", string);
tfree(oldstring);
return (NULL); return (NULL);
} }
wl = cp_varwl(v); wl = cp_varwl(v);
@ -828,7 +845,7 @@ vareval(char *string)
up--, low--; up--, low--;
wl = wl_range(wl, low, up); wl = wl_range(wl, low, up);
} }
tfree(oldstring);
return (wl); return (wl);
} }

Loading…
Cancel
Save