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: fix memory leak in dwarf2read.c


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;
 


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