This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Avoid memory leak in gdb_setup_readline


  gdb_stdout and gdb_stderr are first set
in captured_main function,
  and then overwritten in gdb_setup_readline.

  The patch below fixes it.
  I verified that the different aliases
that are set tp gdb_stdout or gdb_stderr
inside captured_main also are set to the new values
inside gdb_setup_readline.

  The only risk is if we later decide to modify
the code, for instance remove the line
   gdb_stdlog = gdb_stderr;  /* for moment */
from gdb_setup_readline
so that gdb_stdlog would remain pointing to a free'd
ui_file...
  




Pierre Muller
GDB pascal language maintainer


2012-12-11  Pierre Muller  <muller@sourceware.org>

        * event-top.c (gdb_setup_readline): Avoid memory leak if
        gdb_stdout or gdb_stderr are already set.

Index: src/gdb/event-top.c
===================================================================
RCS file: /cvs/src/src/gdb/event-top.c,v
retrieving revision 1.89
diff -u -p -r1.89 event-top.c
--- src/gdb/event-top.c 23 Oct 2012 06:20:49 -0000      1.89
+++ src/gdb/event-top.c 11 Dec 2012 16:50:36 -0000
@@ -953,7 +953,13 @@ gdb_setup_readline (void)
      mess it up here.  The sync stuff should really go away over
      time.  */
   if (!batch_silent)
-    gdb_stdout = stdio_fileopen (stdout);
+    {
+      if (gdb_stdout)
+       ui_file_delete (gdb_stdout);
+      gdb_stdout = stdio_fileopen (stdout);
+    }
+  if (gdb_stderr)
+    ui_file_delete (gdb_stderr);
   gdb_stderr = stdio_fileopen (stderr);
   gdb_stdlog = gdb_stderr;  /* for moment */
   gdb_stdtarg = gdb_stderr; /* for moment */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]