Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix memory leak in python.c:do_start_initialization
@ 2017-03-22 13:11 Philipp Rudo
  2017-03-22 13:11 ` [PATCH] Fix read after xfree in linux_nat_detach Philipp Rudo
  2017-03-22 15:19 ` [PATCH] Fix memory leak in python.c:do_start_initialization Pedro Alves
  0 siblings, 2 replies; 11+ messages in thread
From: Philipp Rudo @ 2017-03-22 13:11 UTC (permalink / raw)
  To: gdb-patches

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.
---
 gdb/python/python.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gdb/python/python.c b/gdb/python/python.c
index 73fb3d0..6b16613 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1535,7 +1535,7 @@ extern initialize_file_ftype _initialize_python;
 static bool
 do_start_initialization ()
 {
-  char *progname;
+  char *progname, *libdir;
 #ifdef IS_PY3K
   int i;
   size_t progsize, count;
@@ -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",
+  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, "");
-- 
2.8.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-04-12  8:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-22 13:11 [PATCH] Fix memory leak in python.c:do_start_initialization Philipp Rudo
2017-03-22 13:11 ` [PATCH] Fix read after xfree in linux_nat_detach Philipp Rudo
2017-03-22 15:07   ` Pedro Alves
2017-03-22 17:17     ` Philipp Rudo
2017-03-22 17:26       ` Pedro Alves
2017-03-23 13:17         ` [PATCH v2] " Philipp Rudo
2017-03-23 13:42           ` Pedro Alves
     [not found]             ` <f712cd1a-cf44-44da-9bf4-3ccd407a76a0@redhat.com>
2017-04-12  8:14               ` Philipp Rudo
2017-03-22 15:19 ` [PATCH] Fix memory leak in python.c:do_start_initialization Pedro Alves
2017-03-22 17:52   ` Philipp Rudo
2017-03-22 18:45     ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox