[PATCH] solib_open, memory leak

msnyder
2007-08-05T03:17:32Z

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