Free sframe context memory on bfd_close

Alan Modra amodra@gmail.com
Wed Feb 11 05:03:54 GMT 2026


Call sframe_decoder_free in _bfd_elf_free_cached_info and correct
other calls to sframe_decoder_free so that sfd_info->stf_ctx is
cleared.  If sfd_info->stf_ctx isn't cleared we get double frees.

	* elf-sframe.c (sframe_decode): Do not pass local var sfd_ctx
	address to sframe_decoder_free, pass the actual context address.
	(_bfd_elf_merge_section_sframe): Likewise.
	* elf.c: Include sframe-api.h.
	(_bfd_elf_free_cached_info): Free sframe info.

diff --git a/bfd/elf-sframe.c b/bfd/elf-sframe.c
index e84b757ca37..c28f1236a2f 100644
--- a/bfd/elf-sframe.c
+++ b/bfd/elf-sframe.c
@@ -282,7 +282,7 @@ _bfd_elf_parse_sframe (bfd *abfd,
 
   if (!sframe_decoder_init_func_bfdinfo (abfd, sec, sfd_info, cookie))
     {
-      sframe_decoder_free (&sfd_ctx);
+      sframe_decoder_free (&sfd_info->sfd_ctx);
       goto fail_no_free;
     }
 
@@ -601,7 +601,7 @@ _bfd_elf_merge_section_sframe (bfd *abfd,
 
   sfd_info->sfd_state = SFRAME_SEC_MERGED;
   /* Free the SFrame decoder context.  */
-  sframe_decoder_free (&sfd_ctx);
+  sframe_decoder_free (&sfd_info->sfd_ctx);
 
   return true;
 }
diff --git a/bfd/elf.c b/bfd/elf.c
index f7437f11fbd..bdb355a6787 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -41,6 +41,7 @@ SECTION
 #include "libbfd.h"
 #define ARCH_SIZE 0
 #include "elf-bfd.h"
+#include "sframe-api.h"
 #include "libiberty.h"
 #include "safe-ctype.h"
 #include "elf-linux-core.h"
@@ -10223,6 +10224,11 @@ _bfd_elf_free_cached_info (bfd *abfd)
 	      struct eh_frame_sec_info *sec_info = sec->sec_info;
 	      free (sec_info->cies);
 	    }
+	  if (sec->sec_info_type == SEC_INFO_TYPE_SFRAME)
+	    {
+	      struct sframe_dec_info *sfd_info = sec->sec_info;
+	      sframe_decoder_free (&sfd_info->sfd_ctx);
+	    }
 	}
       free (tdata->symtab_hdr.contents);
       tdata->symtab_hdr.contents = NULL;

-- 
Alan Modra


More information about the Binutils mailing list