Always free the scopes returned by dwarf_getscopes () when done.

Signed-off-by: Mark Wielaard <m...@redhat.com>
---
 src/ChangeLog   |  5 +++++
 src/addr2line.c | 15 ++++++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 59d87c8..3dbb80d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2015-06-09  Mark Wielaard  <m...@redhat.com>
+
+       * addr2line.c (print_dwarf_function): Always free scopes before
+       returning.
+
 2015-05-30  Mark Wielaard  <m...@redhat.com>
 
        * elfcmp.c (main): Only call memcmp when d_size != 0.
diff --git a/src/addr2line.c b/src/addr2line.c
index 97f988f..0ce854f 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
-- 
2.1.0

Reply via email to