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]

[commit] Fix a memory leak in the DWARF reader


The patch I've been working on all weekend required extensive
benchmarking of the dwarf2 reader.  Benchmarking showed a disturbing
tendency to drive my desktop into swap and I eventually realized I'd
missed freeing some memory when I converted the dwarf2 reader to
support inter-compilation-unit references.

Which was in 2004, by the way, and was the last time I seriously
benchmarked this part of GDB...

Tested on x86_64-linux and committed.  I can now read a reasonably
large number of shared objects one at a time with -readnow without
leaking excessive memory.  There's still a few kilobytes of leaks
per file; things like directory names.

-- 
Daniel Jacobowitz
CodeSourcery

2007-10-21  Daniel Jacobowitz  <dan@codesourcery.com>

	* coffread.c (coff_symfile_finish): Call dwarf2_free_objfile.
	* dwarf2read.c (dwarf2_free_objfile): New.
	* elfread.c (elf_symfile_finish): Call dwarf2_free_objfile.
	* symfile.h (dwarf2_free_objfile): Declare.

Index: coffread.c
===================================================================
RCS file: /cvs/src/src/gdb/coffread.c,v
retrieving revision 1.76
diff -u -p -r1.76 coffread.c
--- coffread.c	11 Oct 2007 19:48:02 -0000	1.76
+++ coffread.c	22 Oct 2007 01:15:45 -0000
@@ -665,6 +665,8 @@ coff_symfile_finish (struct objfile *obj
 
   /* Let stabs reader clean up */
   stabsread_clear_cache ();
+
+  dwarf2_free_objfile (objfile);
 }
 
 
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.232
diff -u -p -r1.232 dwarf2read.c
--- dwarf2read.c	26 Sep 2007 13:59:54 -0000	1.232
+++ dwarf2read.c	22 Oct 2007 01:15:46 -0000
@@ -9964,6 +9964,22 @@ free_one_cached_comp_unit (void *target_
     }
 }
 
+/* Release all extra memory associated with OBJFILE.  */
+
+void
+dwarf2_free_objfile (struct objfile *objfile)
+{
+  dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
+
+  if (dwarf2_per_objfile == NULL)
+    return;
+
+  /* Cached DIE trees use xmalloc and the comp_unit_obstack.  */
+  free_cached_comp_units (NULL);
+
+  /* Everything else should be on the objfile obstack.  */
+}
+
 /* A pair of DIE offset and GDB type pointer.  We store these
    in a hash table separate from the DIEs, and preserve them
    when the DIEs are flushed out of cache.  */
Index: elfread.c
===================================================================
RCS file: /cvs/src/src/gdb/elfread.c,v
retrieving revision 1.64
diff -u -p -r1.64 elfread.c
--- elfread.c	19 Oct 2007 12:26:33 -0000	1.64
+++ elfread.c	22 Oct 2007 01:15:46 -0000
@@ -709,6 +709,8 @@ elf_symfile_finish (struct objfile *objf
     {
       xfree (objfile->deprecated_sym_stab_info);
     }
+
+  dwarf2_free_objfile (objfile);
 }
 
 /* ELF specific initialization routine for reading symbols.
Index: symfile.h
===================================================================
RCS file: /cvs/src/src/gdb/symfile.h,v
retrieving revision 1.42
diff -u -p -r1.42 symfile.h
--- symfile.h	24 Sep 2007 21:48:29 -0000	1.42
+++ symfile.h	22 Oct 2007 01:15:46 -0000
@@ -365,6 +365,8 @@ extern int dwarf2_has_info (struct objfi
 extern void dwarf2_build_psymtabs (struct objfile *, int);
 extern void dwarf2_build_frame_info (struct objfile *);
 
+void dwarf2_free_objfile (struct objfile *);
+
 /* From mdebugread.c */
 
 /* Hack to force structures to exist before use in parameter list.  */


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