From: Mark Wielaard Date: Tue, 9 Jun 2015 22:22:58 +0000 (+0200) Subject: addr2line: Fix memory leak in print_dwarf_function. X-Git-Tag: elfutils-0.162~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5aa90b90adcce527ea3eb098990c809ab69cbf64;p=thirdparty%2Felfutils.git addr2line: Fix memory leak in print_dwarf_function. Always free the scopes returned by dwarf_getscopes () when done. Signed-off-by: Mark Wielaard --- diff --git a/src/ChangeLog b/src/ChangeLog index 35c68c78b..15e6faea9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2015-06-09 Mark Wielaard + + * addr2line.c (print_dwarf_function): Always free scopes before + returning. + 2015-06-09 Mark Wielaard * strip.c (handle_ar): Mark as unused. diff --git a/src/addr2line.c b/src/addr2line.c index 97f988ff7..0ce854f6a 100644 --- a/src/addr2line.c +++ b/src/addr2line.c @@ -330,6 +330,7 @@ print_dwarf_function (Dwfl_Module *mod, Dwarf_Addr addr) if (nscopes <= 0) return false; + bool res = false; for (int i = 0; i < nscopes; ++i) switch (dwarf_tag (&scopes[i])) { @@ -337,23 +338,25 @@ print_dwarf_function (Dwfl_Module *mod, Dwarf_Addr addr) { const char *name = get_diename (&scopes[i]); if (name == NULL) - return false; + goto done; printf ("%s%c", symname (name), pretty ? ' ' : '\n'); - return true; + res = true; + goto done; } case DW_TAG_inlined_subroutine: { const char *name = get_diename (&scopes[i]); if (name == NULL) - return false; + goto done; /* When using --pretty-print we only show inlines on their own line. Just print the first subroutine name. */ if (pretty) { printf ("%s ", symname (name)); - return true; + res = true; + goto done; } else printf ("%s inlined", symname (name)); @@ -414,7 +417,9 @@ print_dwarf_function (Dwfl_Module *mod, Dwarf_Addr addr) } } - return false; +done: + free (scopes); + return res; } static void