]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Don't leak arange if we cannot figure out which CU it belongs to.
authorMark Wielaard <mark@klomp.org>
Tue, 5 Jun 2018 20:41:45 +0000 (22:41 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 8 Jun 2018 10:03:14 +0000 (12:03 +0200)
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 <mark@klomp.org>
libdw/ChangeLog
libdw/dwarf_getaranges.c

index f0ce901de142ede3c596f7e361d531175a9fb0d3..661fa9df4fa74f1dad27c31909938193e3928d06 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-05  Mark Wielaard  <mark@klomp.org>
+
+       * dwarf_getaranges (dwarf_getaranges): Free new_arange if
+       __libdw_findcu fails.
+
 2018-06-05  Mark Wielaard  <mark@klomp.org>
 
        * dwarf_getsrclines.c (read_srclines): Define dirarray early and
index 50a98cf166e082366f0d99f3610fe00cb9388a13..bff9c86021a40fb1346e2ac278cb2c9b163f5de7 100644 (file)
@@ -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;