sframe memory leak

Message ID Z4ekA65tPn93g3p1@squeak.grove.modra.org
State New
Headers
Series sframe memory leak |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Alan Modra Jan. 15, 2025, 12:03 p.m. UTC
  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.
  

Patch

diff --git a/bfd/elf-sframe.c b/bfd/elf-sframe.c
index abc5c525f6f..67ed874e025 100644
--- a/bfd/elf-sframe.c
+++ b/bfd/elf-sframe.c
@@ -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;