From d9a35ea0d5c64c19dd635ae578e0028df8f66d6a Mon Sep 17 00:00:00 2001
From: Sisyphus-wang <43361974+Sisyphus-wang@users.noreply.github.com>
Date: Fri, 11 Jul 2025 15:14:48 +0800
Subject: [PATCH] Update mpeg_l3_encode.c

fix memoryLeak bug

CVE: CVE-2025-56226
Upstream-Status: Backport [https://github.com/libsndfile/libsndfile/commit/d9a35ea0d5c64c19dd635ae578e0028df8f66d6a]
Signed-off-by: Peter Marko <peter.marko@siemens.com>
---
 src/mpeg_l3_encode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/mpeg_l3_encode.c b/src/mpeg_l3_encode.c
index 97324f79..04b1d501 100644
--- a/src/mpeg_l3_encode.c
+++ b/src/mpeg_l3_encode.c
@@ -87,7 +87,8 @@ mpeg_l3_encoder_init (SF_PRIVATE *psf, int info_tag)
 	if (! (pmpeg->lamef = lame_init ()))
 		return SFE_MALLOC_FAILED ;
 
-	pmpeg->compression = -1.0 ; /* Unset */
+	psf->codec_close	= mpeg_l3_encoder_close ; /* Set psf->codec_close early*/
+ 	pmpeg->compression = -1.0 ; /* Unset */
 
 	lame_set_in_samplerate (pmpeg->lamef, psf->sf.samplerate) ;
 	lame_set_num_channels (pmpeg->lamef, psf->sf.channels) ;
@@ -115,7 +116,6 @@ mpeg_l3_encoder_init (SF_PRIVATE *psf, int info_tag)
 		}
 
 	psf->sf.seekable	= 0 ;
-	psf->codec_close	= mpeg_l3_encoder_close ;
 	psf->byterate		= mpeg_l3_encoder_byterate ;
 	psf->datalength		= 0 ;
 
