]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sframe memory leak
authorAlan Modra <amodra@gmail.com>
Sat, 11 Jan 2025 05:20:20 +0000 (15:50 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 15 Jan 2025 12:07:16 +0000 (22:37 +1030)
This is another case where an array isn't freed anywhere and needs to
persist a while, so allocate it with bfd_alloc.

* elf-sframe.c (sframe_decoder_init_func_bfdinfo): Add abfd
param.  bfd_zalloc std_func_bfdinfo.
(_bfd_elf_parse_sframe): Adjust to suit.

bfd/elf-sframe.c

index abc5c525f6f0bc9de7fc085186da205691254fef..67ed874e02524e9fb9ce69221305eeb50c488634 100644 (file)
@@ -97,7 +97,8 @@ sframe_decoder_set_func_reloc_index (struct sframe_dec_info *sfd_info,
    needed for linking SEC.  Returns TRUE if setup is done successfully.  */
 
 static bool
-sframe_decoder_init_func_bfdinfo (asection *sec,
+sframe_decoder_init_func_bfdinfo (bfd *abfd,
+                                 asection *sec,
                                  struct sframe_dec_info *sfd_info,
                                  struct elf_reloc_cookie *cookie)
 {
@@ -109,11 +110,9 @@ sframe_decoder_init_func_bfdinfo (asection *sec,
 
   /* Allocate and clear the memory.  */
   func_bfdinfo_size = (sizeof (struct sframe_func_bfdinfo)) * fde_count;
-  sfd_info->sfd_func_bfdinfo
-    = (struct sframe_func_bfdinfo*) bfd_malloc (func_bfdinfo_size);
+  sfd_info->sfd_func_bfdinfo = bfd_zalloc (abfd, func_bfdinfo_size);
   if (sfd_info->sfd_func_bfdinfo == NULL)
     return false;
-  memset (sfd_info->sfd_func_bfdinfo, 0, func_bfdinfo_size);
 
   /* For linker generated .sframe sections, we have no relocs.  Skip.  */
   if ((sec->flags & SEC_LINKER_CREATED) && cookie->rels == NULL)
@@ -224,7 +223,7 @@ _bfd_elf_parse_sframe (bfd *abfd,
        sframe_decode in case of error.  */
     goto fail_no_free;
 
-  if (!sframe_decoder_init_func_bfdinfo (sec, sfd_info, cookie))
+  if (!sframe_decoder_init_func_bfdinfo (abfd, sec, sfd_info, cookie))
     {
       sframe_decoder_free (&sfd_ctx);
       goto fail_no_free;