]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Plug leak in .debug_abbrev abbreviation store
authorPetr Machata <pmachata@redhat.com>
Mon, 30 Nov 2009 15:22:01 +0000 (16:22 +0100)
committerPetr Machata <pmachata@redhat.com>
Wed, 18 Aug 2010 12:55:15 +0000 (14:55 +0200)
src/dwarflint/check_debug_abbrev.cc
src/dwarflint/low.h

index f5efe9ff354f04b0b7b9252c05373cec02ab77b2..2271d2b7c6d2ff949e41ae90d6a3b5102beba428 100644 (file)
 #include <cassert>
 #include <algorithm>
 
-void
-abbrev_table_free (struct abbrev_table *abbr)
-{
-  for (struct abbrev_table *it = abbr; it != NULL; )
-    {
-      for (size_t i = 0; i < it->size; ++i)
-       free (it->abbr[i].attribs);
-      free (it->abbr);
-
-      struct abbrev_table *temp = it;
-      it = it->next;
-      free (temp);
-    }
-}
-
 struct abbrev *
 abbrev_table_find_abbrev (struct abbrev_table const *abbrevs,
                          uint64_t abbrev_code)
@@ -469,3 +454,19 @@ check_debug_abbrev::check_debug_abbrev (dwarflint &lint)
   , abbrevs (load_debug_abbrev (lint, _m_sec_abbr->sect, _m_sec_abbr->file))
 {
 }
+
+check_debug_abbrev::~check_debug_abbrev ()
+{
+  // xxx So using new[]/delete[] would be nicer (delete ignores
+  // const-ness), but I'm not dipping into that right now.  Just cast
+  // away the const, we're in the dtor so what the heck.
+  abbrev_map &my_abbrevs = const_cast<abbrev_map &> (abbrevs);
+
+  for (abbrev_map::iterator it = my_abbrevs.begin ();
+       it != my_abbrevs.end (); ++it)
+    {
+      for (size_t i = 0; i < it->second.size; ++i)
+       free (it->second.abbr[i].attribs);
+      free (it->second.abbr);
+    }
+}
index 84d1b048bba2dcc775673b18d868dd329d466319..f15df275fabf2de62915da43ca43250a03ccaac2 100644 (file)
@@ -91,7 +91,6 @@ extern "C"
   };
 
   // xxx some of that will go away
-  extern void abbrev_table_free (struct abbrev_table *abbr);
   extern struct abbrev *abbrev_table_find_abbrev (struct abbrev_table const *abbrevs,
                                                  uint64_t abbrev_code);
   extern bool read_rel (struct elf_file *file, struct sec *sec,