]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Free symtab_hdr.contents and a cache_size correction
authorAlan Modra <amodra@gmail.com>
Sat, 11 Jan 2025 05:26:45 +0000 (15:56 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 15 Jan 2025 12:07:16 +0000 (22:37 +1030)
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.

bfd/elf.c
bfd/elflink.c

index a7d23bbd83c3c85f042985dbc038cea79b592ef1..d37f16e974bebec78d5db02a0bf80eb8c6c8c249 100644 (file)
--- 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);
index 8c130dc64744302789bd5a782902b16e0307af98..91c77c211ef065a77883004eb696adacd92a00be 100644 (file)
@@ -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;