This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: PATCH: readline/histexpand.c, resource leak
- From: Jim Blandy <jimb at codesourcery dot com>
- To: msnyder at sonic dot net
- Cc: gdb-patches at sourceware dot org, bug-readline at gnu dot org
- Date: Tue, 14 Aug 2007 17:01:04 -0700
- Subject: Re: PATCH: readline/histexpand.c, resource leak
- References: <10015.12.7.175.2.1185934493.squirrel@webmail.sonic.net>
It seems to me that 'words' is a malloc'ed array of malloc'ed strings,
so 'free (words)' still leaks storage.
msnyder@sonic.net writes:
> 2007-07-31 Michael Snyder <msnyder@access-company.com>
>
> * histexpand.c (history_find_word): Resource leak.
>
> 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 1 Aug 2007 02:08:51 -0000
> *************** history_find_word (line, ind)
> *** 1581,1588 ****
> 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]);
> --- 1581,1594 ----
> int i, wind;
>
> words = history_tokenize_internal (line, ind, &wind);
> ! if (words == NULL)
> return ((char *)NULL);
> + if (wind == -1)
> + {
> + free (words);
> + return ((char *)NULL);
> + }
> +
> s = words[wind];
> for (i = 0; i < wind; i++)
> free (words[i]);