Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] solib_open, memory leak
@ 2007-08-05  3:17 msnyder
  2007-08-06 22:28 ` Jim Blandy
  0 siblings, 1 reply; 8+ messages in thread
From: msnyder @ 2007-08-05  3:17 UTC (permalink / raw)
  To: gdb-patches

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

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).


[-- Attachment #2: 138.txt --]
[-- Type: text/plain, Size: 1921 bytes --]

2007-08-04  Michael Snyder  <msnyder@access-company.com>

	* 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;
  }
  

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-08-09 18:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-05  3:17 [PATCH] solib_open, memory leak msnyder
2007-08-06 22:28 ` Jim Blandy
2007-08-06 22:39   ` Kevin Buettner
2007-08-08 18:29   ` msnyder
2007-08-08 21:46     ` Jim Blandy
2007-08-08 21:58       ` msnyder
2007-08-08 22:08         ` Jim Blandy
2007-08-09 18:37           ` msnyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox