From: msnyder@sonic.net
To: gdb-patches@sourceware.org
Subject: [PATCH] solib_open, memory leak
Date: Sun, 05 Aug 2007 03:17:00 -0000 [thread overview]
Message-ID: <21906.12.7.175.2.1186283848.squirrel@webmail.sonic.net> (raw)
[-- 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;
}
next reply other threads:[~2007-08-05 3:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-05 3:17 msnyder [this message]
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
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=21906.12.7.175.2.1186283848.squirrel@webmail.sonic.net \
--to=msnyder@sonic.net \
--cc=gdb-patches@sourceware.org \
/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