When there is an error with the first entry we might already have allocated
the memory but not yet set cnt to 1. Just always free the memory on error.
free (NULL) is a nop anyway and doesn't matter on a failure path.

Signed-off-by: Mark Wielaard <[email protected]>
---
 libdw/ChangeLog           | 4 ++++
 libdw/dwarf_getpubnames.c | 1 +
 2 files changed, 5 insertions(+)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 577de92..8970ff6 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,9 @@
 2015-06-18  Mark Wielaard  <[email protected]>
 
+       * dwarf_getpubnames.c (get_offsets): Always free mem on error.
+
+2015-06-18  Mark Wielaard  <[email protected]>
+
        * dwarf_getmacros.c (get_macinfo_table): Return NULL when
        dwarf_formudata reports an error.
        (get_table_for_offset): Likewise.
diff --git a/libdw/dwarf_getpubnames.c b/libdw/dwarf_getpubnames.c
index 19f4eae..41b2407 100644
--- a/libdw/dwarf_getpubnames.c
+++ b/libdw/dwarf_getpubnames.c
@@ -127,6 +127,7 @@ get_offsets (Dwarf *dbg)
 
   if (mem == NULL || cnt == 0)
     {
+      free (mem);
       __libdw_seterrno (DWARF_E_NO_ENTRY);
       return -1;
     }
-- 
1.8.3.1

Reply via email to