This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH] libdw: Not leak memory on error in dwarf_getpubnames.
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Thu, 18 Jun 2015 10:44:37 +0200
- Subject: [PATCH] libdw: Not leak memory on error in dwarf_getpubnames.
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@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@redhat.com>
+ * dwarf_getpubnames.c (get_offsets): Always free mem on error.
+
+2015-06-18 Mark Wielaard <mjw@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