From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Subject: RFA: fix memory leak in copy_type_recursive
Date: Sun, 17 Aug 2008 17:40:00 -0000 [thread overview]
Message-ID: <m3fxp3zgrs.fsf@fleche.redhat.com> (raw)
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;
next reply other threads:[~2008-08-17 17:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-17 17:40 Tom Tromey [this message]
2008-08-18 12:20 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3fxp3zgrs.fsf@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox