[PATCH v4 01/14] BFD: Remove null pointer checks for `bfd_hash_table_free' calls

Maciej W. Rozycki macro@orcam.me.uk
Tue Jan 13 01:44:10 GMT 2026


From: Maciej W. Rozycki <macro@redhat.com>

Given that as from commit 90e5645309be ("libiberty: Make `objalloc_free' 
`free'-like WRT null pointer") `bfd_hash_table_free' now returns with no 
action taken when called for a hash table with no allocation present, 
remove null pointer checks guarding invocations.
---
New change in v4, replacing 09/18, 
<https://inbox.sourceware.org/binutils/alpine.DEB.2.21.2511192131280.57987@angie.orcam.me.uk/>.
---
 bfd/opncls.c       |    6 ++----
 binutils/wrstabs.c |    6 ++----
 2 files changed, 4 insertions(+), 8 deletions(-)

binutils-bfd-hash-table-free-call-null.diff
Index: binutils-gdb/bfd/opncls.c
===================================================================
--- binutils-gdb.orig/bfd/opncls.c
+++ binutils-gdb/bfd/opncls.c
@@ -151,8 +151,7 @@ _bfd_delete_bfd (bfd *abfd)
     bfd_free_cached_info (abfd);
 
   /* The target _bfd_free_cached_info may not have done anything..  */
-  if (abfd->section_htab.memory)
-    bfd_hash_table_free (&abfd->section_htab);
+  bfd_hash_table_free (&abfd->section_htab);
   if (abfd->memory)
     objalloc_free (abfd->memory);
 
@@ -186,8 +185,7 @@ DESCRIPTION
 bool
 _bfd_free_cached_info (bfd *abfd)
 {
-  if (abfd->section_htab.memory)
-    bfd_hash_table_free (&abfd->section_htab);
+  bfd_hash_table_free (&abfd->section_htab);
 
   abfd->sections = NULL;
   abfd->section_last = NULL;
Index: binutils-gdb/binutils/wrstabs.c
===================================================================
--- binutils-gdb.orig/binutils/wrstabs.c
+++ binutils-gdb/binutils/wrstabs.c
@@ -555,10 +555,8 @@ write_stabs_in_sections_debugging_info (
   free (info.type_cache.function_types);
   free (info.type_cache.reference_types);
   free (info.type_cache.struct_types);
-  if (info.typedef_hash.table.memory)
-    bfd_hash_table_free (&info.typedef_hash.table);
-  if (info.strhash.table.memory)
-    bfd_hash_table_free (&info.strhash.table);
+  bfd_hash_table_free (&info.typedef_hash.table);
+  bfd_hash_table_free (&info.strhash.table);
   return ret;
 }
 


More information about the Binutils mailing list