This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] libdwfl: Fix memory leak in cu.c on bad DWARF.


If libdw dwarf_offdie fails free cu structure.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libdwfl/ChangeLog |    4 ++++
 libdwfl/cu.c      |    5 ++++-
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index d325475..4d119fd 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,9 @@
 2013-09-12  Mark Wielaard  <mjw@redhat.com>
 
+	* cu.c (intern_cu): If dwarf_offdie fails free cu.
+
+2013-09-12  Mark Wielaard  <mjw@redhat.com>
+
 	* linux-proc-maps.c (proc_maps_report): Don't fclose FILE in
 	bad_report.
 
diff --git a/libdwfl/cu.c b/libdwfl/cu.c
index 18fc206..40b0201 100644
--- a/libdwfl/cu.c
+++ b/libdwfl/cu.c
@@ -204,7 +204,10 @@ intern_cu (Dwfl_Module *mod, Dwarf_Off cuoff, struct dwfl_cu **result)
 	  /* XXX use non-searching lookup */
 	  Dwarf_Die *die = INTUSE(dwarf_offdie) (mod->dw, cuoff, &cu->die);
 	  if (die == NULL)
-	    return DWFL_E_LIBDW;
+	    {
+	      free (cu);
+	      return DWFL_E_LIBDW;
+	    }
 	  assert (die == &cu->die);
 
 	  struct dwfl_cu **newvec = realloc (mod->cu, ((mod->ncu + 1)
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]