From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/2] Free multidicts from blockvector
Date: Thu, 23 Oct 2025 11:17:34 -0600 [thread overview]
Message-ID: <20251023-mdict-free-v1-2-ad02b2bdd549@tromey.com> (raw)
In-Reply-To: <20251023-mdict-free-v1-0-ad02b2bdd549@tromey.com>
Currently, nothing in the tree ever calls mdict_free. However, code
does heap-allocate some multidicts. A simple way to see this is to
use valgrind, run "gdb -readnow" on the executable created by
gdb.dwarf2/struct-with-sig.exp, and then use "file" to clear the
objfile list. This yields:
==1522843== 144 (16 direct, 128 indirect) bytes in 1 blocks are definitely lost in loss record 905 of 3,005
==1522843== at 0x4843866: malloc (vg_replace_malloc.c:446)
==1522843== by 0x48E397: xmalloc (alloc.c:52)
==1522843== by 0x59DE66: multidictionary* xnew<multidictionary>() (poison.h:102)
==1522843== by 0x59CFF4: mdict_create_hashed_expandable(language) (dictionary.c:965)
==1522843== by 0x50A269: buildsym_compunit::finish_block_internal(symbol*, pending**, pending_block*, dynamic_prop const*, unsigned long, unsigned long, int, int) (buildsym.c:221)
==1522843== by 0x50AE04: buildsym_compunit::end_compunit_symtab_get_static_block(unsigned long, int, int) (buildsym.c:818)
==1522843== by 0x50C4CF: buildsym_compunit::end_expandable_symtab(unsigned long) (buildsym.c:1037)
==1522843== by 0x61DBC6: process_full_type_unit (read.c:4970)
This patch fixes the leaks by calling mdict_free when a blockvector is
destroyed.
---
gdb/block.c | 6 ++++++
gdb/block.h | 2 ++
2 files changed, 8 insertions(+)
diff --git a/gdb/block.c b/gdb/block.c
index 02e6d0e4be2bab2c1b3750a2f396e4bc97b7bc5d..2d8d40ec4eb94a1c891a3f8b48972eff3050e66d 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -842,6 +842,12 @@ blockvector::append_block (struct block *block)
m_blocks.push_back (block);
}
+blockvector::~blockvector ()
+{
+ for (struct block *bl : m_blocks)
+ mdict_free (bl->multidict ());
+}
+
/* Implement 'maint info blocks' command. If passed an argument then
print a list of all blocks at the given address. With no arguments
then list all blocks at the current address of the current inferior. */
diff --git a/gdb/block.h b/gdb/block.h
index 61070619ca7daa7b3310a9c5cd8d6ca86c044ada..98ce5a3839dbb8419c9e3a918d27b3b58485fea4 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -424,6 +424,8 @@ struct blockvector
: m_blocks (nblocks, nullptr)
{}
+ ~blockvector ();
+
/* Return a view on the blocks of this blockvector. */
gdb::array_view<struct block *> blocks ()
{
--
2.49.0
next prev parent reply other threads:[~2025-10-23 17:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-23 17:17 [PATCH 0/2] Fix memory leak with .debug_types Tom Tromey
2025-10-23 17:17 ` [PATCH 1/2] Two bug fixes in mdict_free Tom Tromey
2025-10-23 18:26 ` Simon Marchi
2025-10-23 18:32 ` Simon Marchi
2025-10-23 18:49 ` Tom Tromey
2025-10-23 17:17 ` Tom Tromey [this message]
2025-10-23 18:31 ` [PATCH 2/2] Free multidicts from blockvector Simon Marchi
2025-10-23 18:52 ` Tom Tromey
2025-10-24 14:08 ` Tom Tromey
2025-10-24 16:25 ` Simon Marchi
2025-10-24 18:04 ` Tom Tromey
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=20251023-mdict-free-v1-2-ad02b2bdd549@tromey.com \
--to=tom@tromey.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