From: Mark Wielaard Date: Tue, 5 Jun 2018 20:41:45 +0000 (+0200) Subject: libdw: Don't leak arange if we cannot figure out which CU it belongs to. X-Git-Tag: elfutils-0.172~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab92149d354207f55e912c264a72a258f0132e02;p=thirdparty%2Felfutils.git libdw: Don't leak arange if we cannot figure out which CU it belongs to. In the unlikely case that __libdw_findcu fails to find the associated CU we would leak one arange because it wasn't linked into the arangelist list yet. Make sure to free it immediately. Signed-off-by: Mark Wielaard --- diff --git a/libdw/ChangeLog b/libdw/ChangeLog index f0ce901de..661fa9df4 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2018-06-05 Mark Wielaard + + * dwarf_getaranges (dwarf_getaranges): Free new_arange if + __libdw_findcu fails. + 2018-06-05 Mark Wielaard * dwarf_getsrclines.c (read_srclines): Define dirarray early and diff --git a/libdw/dwarf_getaranges.c b/libdw/dwarf_getaranges.c index 50a98cf16..bff9c8602 100644 --- a/libdw/dwarf_getaranges.c +++ b/libdw/dwarf_getaranges.c @@ -197,7 +197,12 @@ dwarf_getaranges (Dwarf *dbg, Dwarf_Aranges **aranges, size_t *naranges) /* We store the actual CU DIE offset, not the CU header offset. */ Dwarf_CU *cu = __libdw_findcu (dbg, offset, false); if (unlikely (cu == NULL)) - goto fail; + { + /* We haven't gotten a chance to link in the new_arange + into the arangelist, don't leak it. */ + free (new_arange); + goto fail; + } new_arange->arange.offset = __libdw_first_die_off_from_cu (cu); new_arange->next = arangelist;