]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
fix deadlock, leaks users/amerey/thread_safety
authorAaron Merey <amerey@redhat.com>
Fri, 28 Jun 2024 22:42:04 +0000 (18:42 -0400)
committerAaron Merey <amerey@redhat.com>
Fri, 28 Jun 2024 22:42:04 +0000 (18:42 -0400)
libdw/dwarf_begin_elf.c
libdw/dwarf_end.c
libdw/dwarf_hasattr.c
libdw/libdw_find_split_unit.c
libdw/libdw_findcu.c

index 8b806c9091ddb58bad6fb7a8bd1f4a93151f7bff..56abef6a6c5aa91280e826df31525b67a8a00d51 100644 (file)
@@ -358,7 +358,7 @@ valid_p (Dwarf *result)
          result->fake_loc_cu->offset_size = 4;
          result->fake_loc_cu->version = 4;
          result->fake_loc_cu->split = NULL;
-         result->fake_loc_cu->locs_tree.root = NULL;
+         eu_search_tree_init (&result->fake_loc_cu->locs_tree);
        }
     }
 
@@ -386,7 +386,7 @@ valid_p (Dwarf *result)
          result->fake_loclists_cu->offset_size = 4;
          result->fake_loclists_cu->version = 5;
          result->fake_loclists_cu->split = NULL;
-         result->fake_loclists_cu->locs_tree.root = NULL;
+         eu_search_tree_init (&result->fake_loclists_cu->locs_tree);
        }
     }
 
@@ -419,7 +419,7 @@ valid_p (Dwarf *result)
          result->fake_addr_cu->offset_size = 4;
          result->fake_addr_cu->version = 5;
          result->fake_addr_cu->split = NULL;
-         result->fake_addr_cu->locs_tree.root = NULL;
+         eu_search_tree_init (&result->fake_addr_cu->locs_tree);
        }
     }
 
index cd9d04577fd3941c5e836bfc936cbe4efb4c2780..60a3e4fda6670a468eac20cfa3ceacdd3f22f95f 100644 (file)
@@ -61,13 +61,13 @@ static void
 cu_free (void *arg)
 {
   struct Dwarf_CU *p = (struct Dwarf_CU *) arg;
+  eu_search_tree_fini (&p->locs_tree, noop_free);
 
   /* Only free the CU internals if its not a fake CU.  */
   if (p != p->dbg->fake_loc_cu && p != p->dbg->fake_loclists_cu
      && p != p->dbg->fake_addr_cu)
     {
       Dwarf_Abbrev_Hash_free (&p->abbrev_hash);
-      eu_search_tree_fini (&p->locs_tree, noop_free);
 
       /* Free split dwarf one way (from skeleton to split).  */
       if (p->unit_type == DW_UT_skeleton
index d5dde5912af3538de4aa50b1cd5c57f07fb50d55..08c28845ea523531bcbadbbdb8acbb8a87442b63 100644 (file)
@@ -44,13 +44,9 @@ dwarf_hasattr (Dwarf_Die *die, unsigned int search_name)
   if (die == NULL)
     return 0;
 
-  //rwlock_wrlock(die_abbrev_lock);
-
   /* Find the abbreviation entry.  */
   Dwarf_Abbrev *abbrevp = __libdw_dieabbrev (die, NULL);
 
-  //rwlock_unlock(die_abbrev_lock);
-
   if (unlikely (abbrevp == DWARF_END_ABBREV))
     {
       __libdw_seterrno (DWARF_E_INVALID_DWARF);
index 323579cc010ea5f9dfca7542e6a3d4e4fc50ca0f..e70e47e1c7b51890b18f4564d6e74b69b9bbfb82 100644 (file)
@@ -157,7 +157,7 @@ Dwarf_CU *
 internal_function
 __libdw_find_split_unit (Dwarf_CU *cu)
 {
-  rwlock_unlock(cu_split_lock);
+  rwlock_wrlock(cu_split_lock);
 
   /* Only try once.  */
   if (cu->split != (Dwarf_CU *) -1)
@@ -215,8 +215,6 @@ __libdw_find_split_unit (Dwarf_CU *cu)
        }
     }
 
-  rwlock_wrlock(cu_split_lock);
-
   /* If we found nothing, make sure we don't try again.  */
   if (cu->split == (Dwarf_CU *) -1)
       cu->split = NULL;
index 93ed2570ab7ffca83955db1630c298cf7c62d3a0..3315dc7c91566bf0d222d1914d846985e4603975 100644 (file)
@@ -171,8 +171,6 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
   newp->orig_abbrev_offset = newp->last_abbrev_offset = abbrev_offset;
   newp->files = NULL;
   newp->lines = NULL;
-  newp->locs_tree.root = NULL;
-  rwlock_init (newp->locs_tree.lock);
   newp->split = (Dwarf_CU *) -1;
   newp->base_address = (Dwarf_Addr) -1;
   newp->addr_base = (Dwarf_Off) -1;
@@ -182,6 +180,7 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
 
   newp->startp = data->d_buf + newp->start;
   newp->endp = data->d_buf + newp->end;
+  eu_search_tree_init (&newp->locs_tree);
 
   /* v4 debug type units have version == 4 and unit_type == DW_UT_type.  */
   if (debug_types)