[PATCH] libdw: Not leak memory on error in dwarf_getpubnames.

Mark Wielaard mjw at redhat.com
Thu Jun 18 08:44:37 UTC 2015


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 <mjw at redhat.com>
---
 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  <mjw at redhat.com>
 
+	* dwarf_getpubnames.c (get_offsets): Always free mem on error.
+
+2015-06-18  Mark Wielaard  <mjw at redhat.com>
+
 	* 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



More information about the elfutils-devel mailing list