Browse Source

dotcards.c: plug some memory leaks

pre-master-46
h_vogt 13 years ago
committed by rlar
parent
commit
3cc06c8e49
  1. 25
      src/frontend/dotcards.c

25
src/frontend/dotcards.c

@ -57,7 +57,7 @@ void
ft_dotsaves(void) ft_dotsaves(void)
{ {
wordlist *iline, *wl = NULL; wordlist *iline, *wl = NULL;
char *s;
char *s, *fr;
if (!ft_curckt) /* Shouldn't happen. */ if (!ft_curckt) /* Shouldn't happen. */
return; return;
@ -65,11 +65,14 @@ ft_dotsaves(void)
for (iline = ft_curckt->ci_commands; iline; iline = iline->wl_next) for (iline = ft_curckt->ci_commands; iline; iline = iline->wl_next)
if (ciprefix(".save", iline->wl_word)) { if (ciprefix(".save", iline->wl_word)) {
s = iline->wl_word; s = iline->wl_word;
(void) gettok(&s);
/* skip .save */
fr = gettok(&s);
tfree(fr);
wl = wl_append(wl, gettoks(s)); wl = wl_append(wl, gettoks(s));
} }
com_save(wl); com_save(wl);
wl_free(wl);
} }
@ -561,7 +564,7 @@ fixem(char *string)
wordlist * wordlist *
gettoks(char *s) gettoks(char *s)
{ {
char *t;
char *t, *s0;
char *l, *r, *c; /* left, right, center/comma */ char *l, *r, *c; /* left, right, center/comma */
wordlist *wl, *list, **prevp; wordlist *wl, *list, **prevp;
@ -569,15 +572,25 @@ gettoks(char *s)
list = NULL; list = NULL;
prevp = &list; prevp = &list;
if (strstr(s, "(")) s = stripWhiteSpacesInsideParens(s);
/* stripWhite.... uses copy() to return a malloc'ed s, so we have to free it,
using s0 as its starting address */
if (strstr(s, "("))
s0 = s = stripWhiteSpacesInsideParens(s);
else
s0 = s = copy(s);
while ((t = gettok(&s)) != NULL) { while ((t = gettok(&s)) != NULL) {
if (*t == '(')
if (*t == '(') {
/* gettok uses copy() to return a malloc'ed t, so we have to free it */
tfree(t);
continue; continue;
}
l = strrchr(t, '('/*)*/); l = strrchr(t, '('/*)*/);
if (!l) { if (!l) {
wl = wl_cons(copy(t), NULL); wl = wl_cons(copy(t), NULL);
*prevp = wl; *prevp = wl;
prevp = &wl->wl_next; prevp = &wl->wl_next;
tfree(t);
continue; continue;
} }
@ -609,6 +622,8 @@ gettoks(char *s)
*prevp = wl; *prevp = wl;
prevp = &wl->wl_next; prevp = &wl->wl_next;
} }
tfree(t);
} }
tfree(s0);
return list; return list;
} }
Loading…
Cancel
Save