From: Alan Modra Date: Sat, 4 Jan 2025 03:09:20 +0000 (+1030) Subject: ELF sec_info memory leaks X-Git-Tag: binutils-2_44~271 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=003ced705f6d4c10b7f0fb96acf7ec2db58f902e;p=thirdparty%2Fbinutils-gdb.git ELF sec_info memory leaks 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. --- diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c index 9a43f1f6467..d903e27a676 100644 --- a/bfd/elf-eh-frame.c +++ b/bfd/elf-eh-frame.c @@ -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); diff --git a/bfd/elf-sframe.c b/bfd/elf-sframe.c index 874d7c271e0..abc5c525f6f 100644 --- a/bfd/elf-sframe.c +++ b/bfd/elf-sframe.c @@ -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);