* RFA: fix memory leak in copy_type_recursive
@ 2008-08-17 17:40 Tom Tromey
2008-08-18 12:20 ` Joel Brobecker
0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2008-08-17 17:40 UTC (permalink / raw)
To: gdb-patches
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;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-08-18 12:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-17 17:40 RFA: fix memory leak in copy_type_recursive Tom Tromey
2008-08-18 12:20 ` Joel Brobecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox