Re: PATCH: readline/histexpand.c, resource leak

msnyder
2007-08-15T00:38:00Z

[-- Attachment #1: Type: text/plain, Size: 289 bytes --]

>
> It seems to me that 'words' is a malloc'ed array of malloc'ed strings,
> so 'free (words)' still leaks storage.

Yeaaaahh... maybe the attached is better? Or is this use
of goto a little opaque?

By the way, are we maintaining our own readline fork?
Should I check these in locally?

[-- Attachment #2: 130b.txt --]
[-- Type: text/plain, Size: 1107 bytes --]

Index: histexpand.c
===================================================================
RCS file: /cvs/src/src/readline/histexpand.c,v
retrieving revision 1.6
diff -p -r1.6 histexpand.c
*** histexpand.c 5 May 2006 18:26:12 -0000 1.6
--- histexpand.c 15 Aug 2007 00:37:32 -0000
*************** history_find_word (line, ind)
*** 1577,1591 ****
char *line;
int ind;
{
! char **words, *s;
int i, wind;

words = history_tokenize_internal (line, ind, &wind);
! if (wind == -1 || words == 0)
! return ((char *)NULL);
s = words[wind];
for (i = 0; i < wind; i++)
free (words[i]);
for (i = wind + 1; words[i]; i++)
free (words[i]);
free (words);
--- 1577,1595 ----
char *line;
int ind;
{
! char **words, *s = NULL;
int i, wind;

words = history_tokenize_internal (line, ind, &wind);
! if (words == NULL)
! return NULL;
! if (wind == -1)
! goto bail;
!
s = words[wind];
for (i = 0; i < wind; i++)
free (words[i]);
+ bail:
for (i = wind + 1; words[i]; i++)
free (words[i]);
free (words);