]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: sframe: fix memory leak of remember_fre
authorIndu Bhagat <indu.bhagat@oracle.com>
Tue, 16 Dec 2025 19:54:07 +0000 (11:54 -0800)
committerIndu Bhagat <indu.bhagat@oracle.com>
Tue, 16 Dec 2025 19:54:07 +0000 (11:54 -0800)
While at it, use the same pattern for cleaning up memory in
sframe_xlate_ctx_cleanup.

gas/
* gen-sframe.c (sframe_xlate_ctx_cleanup): Use the same pattern
for free'ing memory consistently.
(sframe_xlate_ctx_finalize): Free up remember_fre.

gas/gen-sframe.c

index 0d6edd362cbc54b977cda6f7c0a9d93bd6b72ec5..f31cbaee060e19d5d8af0cf4a98fd1943fde5a62 100644 (file)
@@ -924,7 +924,9 @@ sframe_xlate_ctx_cleanup (struct sframe_xlate_ctx *xlate_ctx)
 {
   sframe_row_entry_free (xlate_ctx->first_fre);
   XDELETE (xlate_ctx->remember_fre);
+  xlate_ctx->remember_fre = NULL;
   XDELETE (xlate_ctx->cur_fre);
+  xlate_ctx->cur_fre = NULL;
 }
 
 /* Transfer the state from the SFrame translation context to the SFrame FDE.  */
@@ -936,6 +938,10 @@ sframe_xlate_ctx_finalize (struct sframe_xlate_ctx *xlate_ctx,
   sframe_fde->dw_fde = xlate_ctx->dw_fde;
   sframe_fde->sframe_fres = xlate_ctx->first_fre;
   sframe_fde->num_fres = xlate_ctx->num_xlate_fres;
+  /* remember_fre is cloned copy of the applicable fre (where necessary).
+     Since this is not included in the list of sframe_fres, free it.  */
+  XDELETE (xlate_ctx->remember_fre);
+  xlate_ctx->remember_fre = NULL;
 }
 
 /* Add the given FRE in the list of frame row entries in the given FDE