[PATCH 03/10] libsframe: fix memory leak in sframe_decode
Indu Bhagat
ibhagatgnu@gmail.com
Thu Aug 27 22:41:39 GMT 2026
From: Indu Bhagat <indu.bhagat@oracle.com>
If dctx is successfully allocated by malloc, but the subsequent malloc
for tempbuf fails, sframe_decode () immediately returns NULL without
freeing dctx. This leaks the newly allocated sframe_decoder_ctx
structure.
Change the return on tempbuf == NULL to jump to decode_fail_free to
address this.
---
libsframe/sframe.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libsframe/sframe.c b/libsframe/sframe.c
index 712dd0fdb68..d50a9e5689b 100644
--- a/libsframe/sframe.c
+++ b/libsframe/sframe.c
@@ -1448,7 +1448,10 @@ sframe_decode (const char *sf_buf, size_t sf_size, int *errp)
/* Allocate a new buffer and initialize it. */
char *tempbuf = malloc (sf_size * sizeof (char));
if (tempbuf == NULL)
- return sframe_ret_set_errno (errp, SFRAME_ERR_NOMEM);
+ {
+ sframe_ret_set_errno (errp, SFRAME_ERR_NOMEM);
+ goto decode_fail_free;
+ }
memcpy (tempbuf, sf_buf, sf_size);
/* Flip the header first. */
--
2.43.0
More information about the Binutils
mailing list