From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17490 invoked by alias); 15 Aug 2007 00:38:00 -0000 Received: (qmail 17419 invoked by uid 22791); 15 Aug 2007 00:38:00 -0000 X-Spam-Check-By: sourceware.org Received: from a.mail.sonic.net (HELO a.mail.sonic.net) (64.142.16.245) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 15 Aug 2007 00:37:54 +0000 Received: from webmail.sonic.net (b.webmail.sonic.net [64.142.100.148]) by a.mail.sonic.net (8.13.8.Beta0-Sonic/8.13.7) with ESMTP id l7F0bl8p024485; Tue, 14 Aug 2007 17:37:47 -0700 Received: from 12.7.175.2 (SquirrelMail authenticated user msnyder) by webmail.sonic.net with HTTP; Tue, 14 Aug 2007 17:37:47 -0700 (PDT) Message-ID: <16798.12.7.175.2.1187138267.squirrel@webmail.sonic.net> In-Reply-To: References: <10015.12.7.175.2.1185934493.squirrel@webmail.sonic.net> Date: Wed, 15 Aug 2007 00:38:00 -0000 Subject: Re: PATCH: readline/histexpand.c, resource leak From: msnyder@sonic.net To: "Jim Blandy" Cc: msnyder@sonic.net, gdb-patches@sourceware.org, bug-readline@gnu.org User-Agent: SquirrelMail/1.4.9a MIME-Version: 1.0 Content-Type: multipart/mixed;boundary="----=_20070814173747_15618" Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-08/txt/msg00303.txt.bz2 ------=_20070814173747_15618 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Content-length: 289 > > 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? ------=_20070814173747_15618 Content-Type: text/plain; name="130b.txt" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="130b.txt" Content-length: 1107 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); ------=_20070814173747_15618--