]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ELF sec_info memory leaks
authorAlan Modra <amodra@gmail.com>
Sat, 4 Jan 2025 03:09:20 +0000 (13:39 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 4 Jan 2025 08:45:56 +0000 (19:15 +1030)
Use the bfd's objalloc memory so we don't need to free anything
attached to elf_section_data sec_info.  Other uses of sec_info that
need to allocate memory already use bfd_alloc.

* elf-eh-frame.c (_bfd_elf_parse_eh_frame): bfd_alloc sec_info.
* elf-sframe.c (_bfd_elf_parse_sframe): Likewise.

bfd/elf-eh-frame.c
bfd/elf-sframe.c

index 9a43f1f6467ca7873b5e85f6feb4ce32f1ef7dca..d903e27a676d46c7c1ebe8114030053c61cdd589 100644 (file)
@@ -655,9 +655,9 @@ _bfd_elf_parse_eh_frame (bfd *abfd, struct bfd_link_info *info,
       REQUIRE (skip_bytes (&buf, end, hdr_length - 4));
     }
 
-  sec_info = (struct eh_frame_sec_info *)
-      bfd_zmalloc (sizeof (struct eh_frame_sec_info)
-                  + (num_entries - 1) * sizeof (struct eh_cie_fde));
+  sec_info = bfd_zalloc (abfd,
+                        (sizeof (struct eh_frame_sec_info)
+                         + (num_entries - 1) * sizeof (struct eh_cie_fde)));
   REQUIRE (sec_info);
 
   /* We need to have a "struct cie" for each CIE in this section.  */
@@ -1050,7 +1050,6 @@ _bfd_elf_parse_eh_frame (bfd *abfd, struct bfd_link_info *info,
     (_("error in %pB(%pA); no .eh_frame_hdr table will be created"),
      abfd, sec);
   hdr_info->u.dwarf.table = false;
-  free (sec_info);
  success:
   _bfd_elf_munmap_section_contents (sec, ehbuf);
   free (local_cies);
index 874d7c271e01635517ae8744b3617a6605c32d5c..abc5c525f6f0bc9de7fc085186da205691254fef 100644 (file)
@@ -214,7 +214,7 @@ _bfd_elf_parse_sframe (bfd *abfd,
   /* Decode the buffer and keep decoded contents for later use.
      Relocations are performed later, but are such that the section's
      size is unaffected.  */
-  sfd_info = bfd_malloc (sizeof (struct sframe_dec_info));
+  sfd_info = bfd_alloc (abfd, sizeof (*sfd_info));
   sf_size = sec->size;
 
   sfd_info->sfd_ctx = sframe_decode ((const char*)sfbuf, sf_size, &decerr);