]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Plug leaks.
authorPetr Machata <pmachata@redhat.com>
Mon, 30 Nov 2009 08:08:43 +0000 (09:08 +0100)
committerPetr Machata <pmachata@redhat.com>
Wed, 18 Aug 2010 12:55:14 +0000 (14:55 +0200)
src/dwarflint/check_debug_info.cc
src/dwarflint/checks-low.hh
src/dwarflint/low.c
src/dwarflint/low.h

index f4b12237c1c6ff6dde622ccd0f4ca42da5785c4c..aba009a9bc32de374051f9c2bd301097ca80bf20 100644 (file)
@@ -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<cu>::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<cu>::iterator it = cus.begin ();
+       it != cus.end (); ++it)
+    addr_record_free (&it->die_addrs);
+}
index 87690b03e2f35496c13e48956955c5632035eeba..5a53c5e42c85ef23cbf943b26284897eedbc2678 100644 (file)
@@ -122,6 +122,7 @@ public:
   std::vector<cu> cus;
 
   explicit check_debug_info (dwarflint &lint);
+  ~check_debug_info ();
 };
 static reg<check_debug_info> reg_debug_info;
 
index 89e8c60ae236d71624a2be884ec7dbde59fb24f1..04ac6e1b763cb8a4063da48ab9d047984c811fee 100644 (file)
@@ -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)
 {
index 98612a87975e5efc4bd681385bdada9e19fc8a32..84d1b048bba2dcc775673b18d868dd329d466319 100644 (file)
@@ -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);