From: Alan Modra Date: Sat, 11 Jan 2025 05:26:45 +0000 (+1030) Subject: Free symtab_hdr.contents and a cache_size correction X-Git-Tag: binutils-2_44~123 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=049467c758efe4460220f045205dc61fb69ef5ef;p=thirdparty%2Fbinutils-gdb.git Free symtab_hdr.contents and a cache_size correction symtab_hdr.contents looks to be malloc'd memory, except in one case. Change that one case to also be malloc'd and free when we are done. * elf.c (swap_out_syms): bfd_malloc outbound_syms. (_bfd_elf_free_cached_info): Free symtab_hdr.contents. * elflink.c (init_reloc_cookie): Correct cache_size. locsyms is an array of Elf_Internal_Sym. --- diff --git a/bfd/elf.c b/bfd/elf.c index a7d23bbd83c..d37f16e974b 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -8684,7 +8684,7 @@ swap_out_syms (bfd *abfd, } if (_bfd_mul_overflow (symcount + 1, bed->s->sizeof_sym, &amt) - || (outbound_syms = (bfd_byte *) bfd_alloc (abfd, amt)) == NULL) + || (outbound_syms = bfd_malloc (amt)) == NULL) { error_no_mem: bfd_set_error (bfd_error_no_memory); @@ -10125,6 +10125,8 @@ _bfd_elf_free_cached_info (bfd *abfd) _bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info); _bfd_dwarf1_cleanup_debug_info (abfd, &tdata->dwarf1_find_line_info); _bfd_stab_cleanup (abfd, &tdata->line_info); + free (tdata->symtab_hdr.contents); + tdata->symtab_hdr.contents = NULL; } return _bfd_generic_bfd_free_cached_info (abfd); diff --git a/bfd/elflink.c b/bfd/elflink.c index 8c130dc6474..91c77c211ef 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -13829,7 +13829,7 @@ init_reloc_cookie (struct elf_reloc_cookie *cookie, { symtab_hdr->contents = (bfd_byte *) cookie->locsyms; info->cache_size += (cookie->locsymcount - * sizeof (Elf_External_Sym_Shndx)); + * sizeof (Elf_Internal_Sym)); } } return true;