From: Petr Machata Date: Mon, 30 Nov 2009 15:22:01 +0000 (+0100) Subject: dwarflint: Plug leak in .debug_abbrev abbreviation store X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=77300ac4580627ca35a7849222716b0d0a2fd927;p=thirdparty%2Felfutils.git dwarflint: Plug leak in .debug_abbrev abbreviation store --- diff --git a/src/dwarflint/check_debug_abbrev.cc b/src/dwarflint/check_debug_abbrev.cc index f5efe9ff3..2271d2b7c 100644 --- a/src/dwarflint/check_debug_abbrev.cc +++ b/src/dwarflint/check_debug_abbrev.cc @@ -38,21 +38,6 @@ #include #include -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 (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); + } +} diff --git a/src/dwarflint/low.h b/src/dwarflint/low.h index 84d1b048b..f15df275f 100644 --- a/src/dwarflint/low.h +++ b/src/dwarflint/low.h @@ -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,