Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: msnyder@sonic.net
To: "Jim Blandy" <jimb@codesourcery.com>
Cc: msnyder@sonic.net, gdb-patches@sourceware.org, bug-readline@gnu.org
Subject: Re: PATCH: readline/histexpand.c, resource leak
Date: Wed, 15 Aug 2007 00:38:00 -0000	[thread overview]
Message-ID: <16798.12.7.175.2.1187138267.squirrel@webmail.sonic.net> (raw)
In-Reply-To: <m3d4xpr7i7.fsf@codesourcery.com>

[-- 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);

  reply	other threads:[~2007-08-15  0:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-01  2:14 msnyder
2007-08-10 21:32 ` msnyder
2007-08-15  0:01 ` Jim Blandy
2007-08-15  0:38   ` msnyder [this message]
2007-08-15  1:20     ` Daniel Jacobowitz
2007-08-15  1:40       ` msnyder
2007-08-15 21:43     ` Jim Blandy
2007-08-18 20:12   ` [Bug-readline] " Chet Ramey
2007-08-18 20:15     ` msnyder
2007-08-20 17:03     ` Jim Blandy
2007-08-22  2:02       ` Chet Ramey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16798.12.7.175.2.1187138267.squirrel@webmail.sonic.net \
    --to=msnyder@sonic.net \
    --cc=bug-readline@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jimb@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox