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 copy_type_recursive


While reading about types recently, I ran across a memory leak in
copy_type_recursive.

copy_type_recursive enters copied types into a hash table.  The hash
table is allocated with a NULL 'del_f' function -- so entries are
never freed.  However, copy_type_recursive allocates entries using
xmalloc.

This patch fixes the bug by allocating the hash table entry on the
objfile's obstack.  This is ok because this is how the hash table
itself is allocated.

Built & regtested on x86-64 (compile farm).
Ok?

Tom

2008-08-17  Tom Tromey  <tromey@redhat.com>

	* gdbtypes.c (copy_type_recursive): Allocate 'stored' on objfile's
	obstack.

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 939a1dc..bbacee5 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2928,7 +2928,7 @@ copy_type_recursive (struct objfile *objfile,
 
   /* We must add the new type to the hash table immediately, in case
      we encounter this type again during a recursive call below.  */
-  stored = xmalloc (sizeof (struct type_pair));
+  stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
   stored->old = type;
   stored->new = new_type;
   *slot = stored;


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