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]

Re: [RFA] python/py-breakpoint.c, fix memory leak


Tom Tromey wrote:
"Michael" == Michael Snyder <msnyder@vmware.com> writes:

Michael> 2011-02-27 Michael Snyder <msnyder@vmware.com> Michael> * python/py-breakpoint.c (bppy_get_commands): Fix memory leak.

This is good but not sufficient.
I think you also need to install a cleanup for cmdstr after it is
assigned.

Tom

Like this?



2011-02-27  Michael Snyder  <msnyder@vmware.com>

	* python/py-breakpoint.c (bppy_get_commands): Fix memory leak.

Index: python/py-breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-breakpoint.c,v
retrieving revision 1.14
diff -u -p -u -p -r1.14 py-breakpoint.c
--- python/py-breakpoint.c	4 Feb 2011 21:54:16 -0000	1.14
+++ python/py-breakpoint.c	2 Mar 2011 20:45:55 -0000
@@ -489,12 +489,12 @@ bppy_get_commands (PyObject *self, void 
       print_command_lines (uiout, breakpoint_commands (bp), 0);
     }
   ui_out_redirect (uiout, NULL);
-  cmdstr = ui_file_xstrdup (string_file, &length);
   GDB_PY_HANDLE_EXCEPTION (except);
 
+  cmdstr = ui_file_xstrdup (string_file, &length);
+  make_cleanup (xfree, cmdstr);
   result = PyString_Decode (cmdstr, strlen (cmdstr), host_charset (), NULL);
   do_cleanups (chain);
-  xfree (cmdstr);
   return result;
 }
 

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