This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFA: fix memory leak in dwarf2read.c
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 28 Aug 2008 16:12:52 -0600
- Subject: RFA: fix memory leak in dwarf2read.c
- Reply-to: Tom Tromey <tromey at redhat dot com>
I found a memory leak while looking at dwarf2read.
We xstrdup the directory name, but nothing ever frees it.
The simplest fix seemed to be to allocate it on the objfile obstack.
Built and regtested on x86-64 (compile farm).
I also verified this, before and after, with valgrind.
Ok?
Tom
:ADDPATCH dwarf:
2008-08-28 Tom Tromey <tromey@redhat.com>
* dwarf2read.c (dwarf2_build_psymtabs_hard): Copy dirname on
obstack.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 5cb444e..95a85b1 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1529,7 +1529,9 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
objfile->static_psymbols.next);
if (comp_unit_die.dirname)
- pst->dirname = xstrdup (comp_unit_die.dirname);
+ pst->dirname = obsavestring (comp_unit_die.dirname,
+ strlen (comp_unit_die.dirname),
+ &objfile->objfile_obstack);
pst->read_symtab_private = (char *) this_cu;