When there is an error in dwarf_getscopes after the initial scopes
have been allocated, e.g. when looking for the inlined scopes, then
the scopes would leak. Fix this by explicitly free the scopes on error.
https://sourceware.org/bugzilla/show_bug.cgi?id=29434
Signed-off-by: Mark Wielaard <mark@klomp.org>
+2023-02-22 Mark Wielaard <mark@klomp.org>
+
+ * dwarf_getscopes.c (origin_match): Don't free a->scopes.
+ (dwarf_getscopes): Free a->scopes on error.
+
2023-02-20 Mark Wielaard <mark@klomp.org>
* dwarf_begin_elf.c (check_section): Use elf_rawdata.
Dwarf_Die *scopes = realloc (a->scopes, nscopes * sizeof scopes[0]);
if (scopes == NULL)
{
- free (a->scopes);
+ /* a->scopes will be freed by dwarf_getscopes on error. */
__libdw_seterrno (DWARF_E_NOMEM);
return -1;
}
if (result > 0)
*scopes = a.scopes;
+ else if (result < 0)
+ free (a.scopes);
return result;
}