* Set dwarf2 stash pointer earlier
@ 2023-01-09 23:40 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-01-09 23:40 UTC (permalink / raw)
To: binutils
This fixes a memory leak in the vanishingly rare cases (found by
fuzzers of course) when something goes wrong in the save_section_vma,
htab_create_alloc or alloc_trie_leaf calls before *pinfo is written.
If *pinfo is not written, _bfd_dwarf2_cleanup_debug_info won't be able
to free that memory.
* dwarf2.c (_bfd_dwarf2_slurp_debug_info): Save stash pointer
on setting up stash.
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index f689eebbd88..bd431805d2a 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -5408,6 +5408,7 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd,
stash = (struct dwarf2_debug *) bfd_zalloc (abfd, amt);
if (! stash)
return false;
+ *pinfo = stash;
}
stash->orig_bfd = abfd;
stash->debug_sections = debug_sections;
@@ -5433,8 +5434,6 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd,
if (!stash->alt.trie_root)
return false;
- *pinfo = stash;
-
if (debug_bfd == NULL)
debug_bfd = abfd;
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-09 23:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09 23:40 Set dwarf2 stash pointer earlier Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).