ELF sec_info memory leaks
Checks
Commit Message
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.
@@ -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);
@@ -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);