From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25317 invoked by alias); 5 Aug 2007 03:17:32 -0000 Received: (qmail 25282 invoked by uid 22791); 5 Aug 2007 03:17:32 -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; Sun, 05 Aug 2007 03:17:30 +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 l753HSFg028524 for ; Sat, 4 Aug 2007 20:17:28 -0700 Received: from 12.7.175.2 (SquirrelMail authenticated user msnyder) by webmail.sonic.net with HTTP; Sat, 4 Aug 2007 20:17:28 -0700 (PDT) Message-ID: <21906.12.7.175.2.1186283848.squirrel@webmail.sonic.net> Date: Sun, 05 Aug 2007 03:17:00 -0000 Subject: [PATCH] solib_open, memory leak From: msnyder@sonic.net To: gdb-patches@sourceware.org User-Agent: SquirrelMail/1.4.9a MIME-Version: 1.0 Content-Type: multipart/mixed;boundary="----=_20070804201728_45968" 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/msg00097.txt.bz2 ------=_20070804201728_45968 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Content-length: 267 I hope it's not getting to be too late at night for me to do this stuff... If I'm not spacy, solib_open is leaking memory, because openp passes back a malloc buffer for temp_pathname. In order to free it, it has to always be a malloc buffer (hence no alloca etc). ------=_20070804201728_45968 Content-Type: text/plain; name="138.txt" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="138.txt" Content-length: 1921 2007-08-04 Michael Snyder * solib.c (solib_open): Memory leak -- openp returns xmalloc buffer. Index: solib.c =================================================================== RCS file: /cvs/src/src/gdb/solib.c,v retrieving revision 1.94 diff -p -r1.94 solib.c *** solib.c 3 Jul 2007 12:14:43 -0000 1.94 --- solib.c 5 Aug 2007 03:13:49 -0000 *************** solib_open (char *in_pathname, char **fo *** 156,162 **** gdb_sysroot_is_empty = (gdb_sysroot == NULL || *gdb_sysroot == 0); if (! IS_ABSOLUTE_PATH (in_pathname) || gdb_sysroot_is_empty) ! temp_pathname = in_pathname; else { int prefix_len = strlen (gdb_sysroot); --- 156,162 ---- gdb_sysroot_is_empty = (gdb_sysroot == NULL || *gdb_sysroot == 0); if (! IS_ABSOLUTE_PATH (in_pathname) || gdb_sysroot_is_empty) ! temp_pathname = xstrdup (in_pathname); else { int prefix_len = strlen (gdb_sysroot); *************** solib_open (char *in_pathname, char **fo *** 167,173 **** prefix_len--; /* Cat the prefixed pathname together. */ ! temp_pathname = alloca (prefix_len + strlen (in_pathname) + 1); strncpy (temp_pathname, gdb_sysroot, prefix_len); temp_pathname[prefix_len] = '\0'; strcat (temp_pathname, in_pathname); --- 167,173 ---- prefix_len--; /* Cat the prefixed pathname together. */ ! temp_pathname = xmalloc (prefix_len + strlen (in_pathname) + 1); strncpy (temp_pathname, gdb_sysroot, prefix_len); temp_pathname[prefix_len] = '\0'; strcat (temp_pathname, in_pathname); *************** solib_open (char *in_pathname, char **fo *** 226,231 **** --- 226,233 ---- (optionally) found_pathname. */ if (found_pathname != NULL && temp_pathname != NULL) *found_pathname = xstrdup (temp_pathname); + + xfree (temp_pathname); return found_file; } ------=_20070804201728_45968--