aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorPhilipp Rudo <prudo@linux.vnet.ibm.com>2017-03-23 12:22:11 +0100
committerAndreas Arnez <arnez@linux.vnet.ibm.com>2017-03-23 12:22:11 +0100
commit3f2a3564b1c3872e4a380f2484d40ce2495a4835 (patch)
tree4f70b9c9a397ae95de3a2083f04cc3a95027b1d9 /gdb/python
parentad36c6ce7c176a0bade3b3f09b801e65ab5ef93f (diff)
Fix memory leak in python.c:do_start_initialization
When intializing Python the path to the python binary is build the following way progname = concat (ldirname (python_libdir), SLASH_STRING, "bin", SLASH_STRING, "python", (char *) NULL); This is problematic as both concat and ldirname allocate memory for the string they return. Thus the memory allocated by ldirname cannot be accessed afterwards causing a memory leak. Fix it by temporarily storing libdir in a variable and xfree it after concat. gdb/ChangeLog: python/python.c (do_start_initialization): Fix memory leak.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/python.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 73fb3d0295..d814252303 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1550,8 +1550,10 @@ do_start_initialization ()
/foo/bin/python
/foo/lib/pythonX.Y/...
This must be done before calling Py_Initialize. */
- progname = concat (ldirname (python_libdir), SLASH_STRING, "bin",
+ const char *libdir = ldirname (python_libdir);
+ progname = concat (libdir, SLASH_STRING, "bin",
SLASH_STRING, "python", (char *) NULL);
+ xfree (libdir);
#ifdef IS_PY3K
oldloc = xstrdup (setlocale (LC_ALL, NULL));
setlocale (LC_ALL, "");