]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR 33858 Object Attributes v2 memory leaks
authorAlan Modra <amodra@gmail.com>
Tue, 10 Feb 2026 00:04:48 +0000 (10:34 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 10 Feb 2026 00:16:25 +0000 (10:46 +1030)
It is possble for elf_object_p to hit errors after or during the loop
processing sections with bfd_section_from_shdr.  That means we might
have some object attributes malloc'd.  They need cleaning up in
elf_object_p because bfd_check_format_matches only handles tidying of
bfd_alloc memory.

* elfcode.h (elf_object_p): Free object attributes on failure.

bfd/elfcode.h

index d7c82f0797cd5fd4ff2ee5bea0590fc6f7d50709..9e4ff80a02c55005c2ac6ce89e231efb29ee7ef6 100644 (file)
@@ -919,6 +919,11 @@ elf_object_p (bfd *abfd)
   bfd_set_error (bfd_error_wrong_format);
 
  got_no_match:
+  if (abfd->sections != NULL)
+    /* Unlike most early section processing, the object attribute v2
+       code uses bfd_malloc rather than bfd_alloc.  Free memory
+       containing attributes.  */
+    _bfd_elf_cleanup_object_attributes (abfd);
   return NULL;
 }
 \f