This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] Fix memory leak in python.c:do_start_initialization
- From: Andreas Arnez <arnez at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 23 Mar 2017 11:23:37 -0000
- Subject: [binutils-gdb] Fix memory leak in python.c:do_start_initialization
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3f2a3564b1c3872e4a380f2484d40ce2495a4835
commit 3f2a3564b1c3872e4a380f2484d40ce2495a4835
Author: Philipp Rudo <prudo@linux.vnet.ibm.com>
Date: Thu Mar 23 12:22:11 2017 +0100
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.
Diff:
---
gdb/ChangeLog | 4 ++++
gdb/python/python.c | 4 +++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8bb9e21..f69a27e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2017-03-23 Philipp Rudo <prudo@linux.vnet.ibm.com>
+
+ python/python.c (do_start_initialization): Fix memory leak.
+
2017-03-22 Simon Marchi <simon.marchi@polymtl.ca>
* inf-ptrace.c (inf_ptrace_xfer_partial): Get pid from ptid
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 73fb3d0..d814252 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, "");