From 5ddf0bf032403bf1b555571753bf3a00b81e2990 Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Mon, 30 Nov 2009 09:08:43 +0100 Subject: [PATCH] dwarflint: Plug leaks. --- src/dwarflint/check_debug_info.cc | 45 ++++++++++++++++++++++--------- src/dwarflint/checks-low.hh | 1 + src/dwarflint/low.c | 13 --------- src/dwarflint/low.h | 2 -- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/dwarflint/check_debug_info.cc b/src/dwarflint/check_debug_info.cc index f4b12237c..aba009a9b 100644 --- a/src/dwarflint/check_debug_info.cc +++ b/src/dwarflint/check_debug_info.cc @@ -1045,11 +1045,15 @@ check_debug_info::check_info_structural (struct elf_file *file, { cu_head const &head = *it; where const &where = head.where; - cu *cur = (cu *)xcalloc (1, sizeof (struct cu)); - cur->head = &head; - cur->low_pc = (uint64_t)-1; - cur->next = cu_chain; - cu_chain = cur; + { + cu cur; + memset (&cur, 0, sizeof (cur)); + cur.head = &head; + cur.low_pc = (uint64_t)-1; + //cur.next = (cu *)(uintptr_t)0xdead; + cus.push_back (cur); + } + cu &cur = cus.back (); assert (read_ctx_need_data (&ctx, head.total_size)); @@ -1060,7 +1064,7 @@ check_debug_info::check_info_structural (struct elf_file *file, read_ctx_init_sub (&cu_ctx, &ctx, ctx.ptr, cu_end); cu_ctx.ptr += head.head_size; - if (!check_cu_structural (file, &cu_ctx, cur, + if (!check_cu_structural (file, &cu_ctx, &cur, strings, strings_coverage, reloc, &cu_cov)) { @@ -1110,12 +1114,26 @@ check_debug_info::check_info_structural (struct elf_file *file, << ": abbreviation is never used." << std::endl; } + // Relink the CU chain. + { + cu *last = NULL; + for (std::vector::iterator it = cus.begin (); + it != cus.end (); ++it) + { + if (last != NULL) + last->next = &*it; + last = &*it; + } + if (last != NULL) + last->next = NULL; + } + /* We used to check that all CUs have the same address size. Now that we validate address_size of each CU against the ELF header, that's not necessary anymore. */ - bool references_sound = check_global_die_references (cu_chain); + check_global_die_references (&cus.front ()); ref_record_free (&die_refs); if (strings_coverage != NULL) @@ -1129,12 +1147,6 @@ check_debug_info::check_info_structural (struct elf_file *file, coverage_free (strings_coverage); } - if (!success || !references_sound) - { - cu_free (cu_chain); - cu_chain = NULL; - } - /* Reverse the chain, so that it's organized "naturally". Has significant impact on performance when handling loc_ref and range_ref fields in loc/range validation. */ @@ -1184,3 +1196,10 @@ check_debug_info::check_debug_info (dwarflint &lint) if (cus.size () > 0) assert (cus.back ().next == NULL); } + +check_debug_info::~check_debug_info () +{ + for (std::vector::iterator it = cus.begin (); + it != cus.end (); ++it) + addr_record_free (&it->die_addrs); +} diff --git a/src/dwarflint/checks-low.hh b/src/dwarflint/checks-low.hh index 87690b03e..5a53c5e42 100644 --- a/src/dwarflint/checks-low.hh +++ b/src/dwarflint/checks-low.hh @@ -122,6 +122,7 @@ public: std::vector cus; explicit check_debug_info (dwarflint &lint); + ~check_debug_info (); }; static reg reg_debug_info; diff --git a/src/dwarflint/low.c b/src/dwarflint/low.c index 89e8c60ae..04ac6e1b7 100644 --- a/src/dwarflint/low.c +++ b/src/dwarflint/low.c @@ -128,19 +128,6 @@ is_location_attrib (uint64_t name) } } -void -cu_free (struct cu *cu_chain) -{ - for (struct cu *it = cu_chain; it != NULL; ) - { - addr_record_free (&it->die_addrs); - - struct cu *temp = it; - it = it->next; - free (temp); - } -} - static struct cu * cu_find_cu (struct cu *cu_chain, uint64_t offset) { diff --git a/src/dwarflint/low.h b/src/dwarflint/low.h index 98612a879..84d1b048b 100644 --- a/src/dwarflint/low.h +++ b/src/dwarflint/low.h @@ -160,8 +160,6 @@ extern "C" GElf_Sym *end_symbol, const char *description); - extern void cu_free (struct cu *cu_chain); - extern int check_sibling_form (dwarf_version_h ver, uint64_t form); extern bool is_location_attrib (uint64_t name); -- 2.47.3