summaryrefslogtreecommitdiff
path: root/gdb/solib.c
diff options
context:
space:
mode:
authorMichael Snyder <msnyder@specifix.com>2007-08-09 18:37:08 +0000
committerMichael Snyder <msnyder@specifix.com>2007-08-09 18:37:08 +0000
commit245f3646dda2063e5ba1d915ca3591bf729eab63 (patch)
treedf2ae9db3d63cd04243ab30d4da53658aea940dd /gdb/solib.c
parentabf1a9cdee1479b8f1e16a1d551b3183bd10037a (diff)
downloadgdb-245f3646dda2063e5ba1d915ca3591bf729eab63.tar.gz
2007-08-09 Michael Snyder <msnyder@access-company.com>
* solib.c (solib_open): Memory leak -- openp returns xmalloc buffer.
Diffstat (limited to 'gdb/solib.c')
-rw-r--r--gdb/solib.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/gdb/solib.c b/gdb/solib.c
index f522812d427..bd4cf517551 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -176,6 +176,17 @@ solib_open (char *in_pathname, char **found_pathname)
/* Now see if we can open it. */
found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
+ /* We try to find the library in various ways. After each attempt
+ (except for the one above), either found_file >= 0 and
+ temp_pathname is a malloc'd string, or found_file < 0 and
+ temp_pathname does not point to storage that needs to be
+ freed. */
+
+ if (found_file < 0)
+ temp_pathname = NULL;
+ else
+ temp_pathname = xstrdup (temp_pathname);
+
/* If the search in gdb_sysroot failed, and the path name is
absolute at this point, make it relative. (openp will try and open the
file according to its absolute path otherwise, which is not what we want.)
@@ -224,8 +235,13 @@ solib_open (char *in_pathname, char **found_pathname)
/* Done. If not found, tough luck. Return found_file and
(optionally) found_pathname. */
- if (found_pathname != NULL && temp_pathname != NULL)
- *found_pathname = xstrdup (temp_pathname);
+ if (temp_pathname)
+ {
+ if (found_pathname != NULL)
+ *found_pathname = temp_pathname;
+ else
+ xfree (temp_pathname);
+ }
return found_file;
}