On Tue, Dec 18, 2012 at 12:50:12PM -0800, Roland McGrath wrote:
> What about the other error cases in dwarf_begin_elf?

Those should of course clean up too, after Dwarf_Sig8_Hash_init () has
been called. Missed them because they are "real errors", while valid_p ()
is called more often for normal ELF files that just happen to not have
any valid DWARF sections.

Thanks,

Mark
>From 59254427e7c9eeb697de00069a9cb7dc1c908f86 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <[email protected]>
Date: Tue, 18 Dec 2012 14:14:22 +0100
Subject: [PATCH] Fix sig8_hash memory leak in libdw/dwarf_begin_elf.c on
 error.

Signed-off-by: Mark Wielaard <[email protected]>
---
 libdw/ChangeLog         | 7 +++++++
 libdw/dwarf_begin_elf.c | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 0d35ca9..24f4bb4 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,10 @@
+2012-12-18  Mark Wielaard  <[email protected]>
+
+       * dwarf_begin_elf.c (valid_p): Call Dwarf_Sig8_Hash_free if invalid.
+       (check_section): Likewise on error.
+       (scngrp_read): Likewise.
+       (dwarf_begin_elf): Likewise.
+
 2012-10-09  Petr Machata  <[email protected]>
 
        * dwarf_getlocation.c (__libdw_intern_expression): Handle
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index a9c826c..6cf3aa1 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -216,6 +216,7 @@ check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn 
*scn, bool inscngrp)
       /* The section name must be valid.  Otherwise is the ELF file
         invalid.  */
       __libdw_free_zdata (result);
+      Dwarf_Sig8_Hash_free (&result->sig8_hash);
       __libdw_seterrno (DWARF_E_INVALID_ELF);
       free (result);
       return NULL;
@@ -344,6 +345,7 @@ valid_p (Dwarf *result)
       && unlikely (result->sectiondata[IDX_debug_info] == NULL))
     {
       __libdw_free_zdata (result);
+      Dwarf_Sig8_Hash_free (&result->sig8_hash);
       __libdw_seterrno (DWARF_E_NO_DWARF);
       free (result);
       result = NULL;
@@ -375,6 +377,7 @@ scngrp_read (Dwarf *result, Elf *elf, GElf_Ehdr *ehdr, 
Elf_Scn *scngrp)
     {
       /* We cannot read the section content.  Fail!  */
       __libdw_free_zdata (result);
+      Dwarf_Sig8_Hash_free (&result->sig8_hash);
       free (result);
       return NULL;
     }
@@ -391,6 +394,7 @@ scngrp_read (Dwarf *result, Elf *elf, GElf_Ehdr *ehdr, 
Elf_Scn *scngrp)
          /* A section group refers to a non-existing section.  Should
             never happen.  */
          __libdw_free_zdata (result);
+         Dwarf_Sig8_Hash_free (&result->sig8_hash);
          __libdw_seterrno (DWARF_E_INVALID_ELF);
          free (result);
          return NULL;
@@ -471,11 +475,13 @@ dwarf_begin_elf (elf, cmd, scngrp)
     }
   else if (cmd == DWARF_C_WRITE)
     {
+      Dwarf_Sig8_Hash_free (&result->sig8_hash);
       __libdw_seterrno (DWARF_E_UNIMPL);
       free (result);
       return NULL;
     }
 
+  Dwarf_Sig8_Hash_free (&result->sig8_hash);
   __libdw_seterrno (DWARF_E_INVALID_CMD);
   free (result);
   return NULL;
-- 
1.7.11.7

_______________________________________________
elfutils-devel mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/elfutils-devel

Reply via email to