From 130166fc1e36455da4d5b6b7d9a8564d353b9735 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Wed, 11 Feb 2026 09:00:02 +0100 Subject: [PATCH 1/2] ivas_destroy_dec(): remove dependency on format, to avoid a memory leak in case of format switching; see float issue 1526 for details --- lib_com/options.h | 1 + lib_dec/ivas_init_dec.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index c289efb2a4..cca18ed73f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -162,6 +162,7 @@ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define FIX_FLOAT_1522_LTV_MSAN_QMETADATA_ENC_EC3 /* Nokia: float issue 1522: fix uninit MSAN in EC3 of qmetadata encoding */ +#define FIX_FLOAT_1526_DIRAC_MEM_LEAK /* FhG: potential memory leak in DirAC handles in case of format switching */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 6048cd7fa4..9a8c5d8550 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2884,6 +2884,15 @@ void ivas_destroy_dec( /* ISM renderer handle */ ivas_ism_renderer_close( &( st_ivas->hIsmRendererData ) ); +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK + /* ParamISM dec handle */ + ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); + + /* DirAC handles */ + ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); +#else /* DirAC handle */ if ( st_ivas->ivas_format == ISM_FORMAT ) { @@ -2895,6 +2904,7 @@ void ivas_destroy_dec( ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); } +#endif /* SPAR handle */ ivas_spar_dec_close( &( st_ivas->hSpar ), st_ivas->hDecoderConfig->output_Fs, 0 ); -- GitLab From 7950bbdbe0e6035c6c5efce8d9a7d0db7070f910 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Wed, 11 Feb 2026 12:19:28 +0100 Subject: [PATCH 2/2] properly initialize sub-handles/buffers with NULL, avoid depdency in free-functions from codec parameters --- lib_com/ivas_prot.h | 6 +++++ lib_dec/ivas_init_dec.c | 2 +- lib_dec/ivas_ism_dec.c | 6 +++++ lib_dec/ivas_ism_param_dec.c | 45 ++++++++++++++++++++++++++++++++++++ lib_rend/ivas_dirac_rend.c | 14 +++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index aa456627a4..041706b9bd 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1109,11 +1109,17 @@ ivas_error ivas_param_ism_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK +void ivas_param_ism_dec_close( + PARAM_ISM_DEC_HANDLE *hParamIsmDec /* i/o: decoder ParamISM handle */ +); +#else void ivas_param_ism_dec_close( PARAM_ISM_DEC_HANDLE *hParamIsmDec, /* i/o: decoder ParamISM handle */ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ const AUDIO_CONFIG output_config /* i : output audio configuration */ ); +#endif void ivas_ism_dec_digest_tc( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 9a8c5d8550..d2de8e6eae 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2886,7 +2886,7 @@ void ivas_destroy_dec( #ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK /* ParamISM dec handle */ - ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); + ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ) ); /* DirAC handles */ ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 3bfec52ed0..e9bf05b9a1 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -149,7 +149,13 @@ static ivas_error ivas_ism_bitrate_switching_dec( if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM ) { /* Deallocate the ParamISM struct */ +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK + ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ) ); + + ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); +#else ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); +#endif if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 5c3782969b..37ff1a940c 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -430,22 +430,55 @@ ivas_error ivas_param_ism_dec_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) ); } +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK + /* initialize sub-handles with NULL */ + hParamIsmDec->hParamIsm = NULL; + hParamIsmDec->hParamIsmRendering = NULL; +#endif + if ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK + /* initialize buffers in handle with NULL - this handle is also used by other DirAC technologies, and not every technology is initializing all buffers */ + hSpatParamRendCom->azimuth = NULL; + hSpatParamRendCom->elevation = NULL; + hSpatParamRendCom->azimuth2 = NULL; + hSpatParamRendCom->elevation2 = NULL; + hSpatParamRendCom->diffuseness_vector = NULL; + hSpatParamRendCom->energy_ratio1 = NULL; + hSpatParamRendCom->energy_ratio2 = NULL; + hSpatParamRendCom->spreadCoherence = NULL; + hSpatParamRendCom->spreadCoherence2 = NULL; + hSpatParamRendCom->surroundingCoherence = NULL; +#endif + /* Assign memory to Param Object handle */ if ( ( hParamIsmDec->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) ); } +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK + /* initialize sub-handles with NULL */ + hParamIsmDec->hParamIsm->hFbMixer = NULL; +#endif + if ( ( hParamIsmDec->hParamIsmRendering = (PARAM_ISM_RENDERING_HANDLE) malloc( sizeof( PARAM_ISM_RENDERING_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM Rendering handle\n" ) ); } +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK + /* initialize sub-handles/buffers with NULL */ + hParamIsmDec->hParamIsmRendering->proto_matrix = NULL; + hParamIsmDec->hParamIsmRendering->interpolator = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; +#endif + output_Fs = st_ivas->hDecoderConfig->output_Fs; output_config = st_ivas->hDecoderConfig->output_config; @@ -617,11 +650,17 @@ ivas_error ivas_param_ism_dec_open( * Close Param ISM handle *-------------------------------------------------------------------------*/ +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK +void ivas_param_ism_dec_close( + PARAM_ISM_DEC_HANDLE *hParamIsmDec_out /* i/o: decoder DirAC handle */ +) +#else void ivas_param_ism_dec_close( PARAM_ISM_DEC_HANDLE *hParamIsmDec_out, /* i/o: decoder DirAC handle */ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ AUDIO_CONFIG output_config /* i : output audio configuration */ ) +#endif { if ( hParamIsmDec_out != NULL && *hParamIsmDec_out != NULL ) { @@ -635,8 +674,10 @@ void ivas_param_ism_dec_close( hParamIsmDec->hParamIsm = NULL; } +#ifndef FIX_FLOAT_1526_DIRAC_MEM_LEAK if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) ) { +#endif /* Param ISM Rendering */ if ( hParamIsmDec->hParamIsmRendering->interpolator != NULL ) { @@ -648,7 +689,9 @@ void ivas_param_ism_dec_close( free( hParamIsmDec->hParamIsmRendering->proto_matrix ); hParamIsmDec->hParamIsmRendering->proto_matrix = NULL; } +#ifndef FIX_FLOAT_1526_DIRAC_MEM_LEAK } +#endif if ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc != NULL ) { @@ -671,6 +714,7 @@ void ivas_param_ism_dec_close( *hParamIsmDec_out = NULL; } +#ifndef FIX_FLOAT_1526_DIRAC_MEM_LEAK if ( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL ) { if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) @@ -682,6 +726,7 @@ void ivas_param_ism_dec_close( free( *hSpatParamRendCom_out ); *hSpatParamRendCom_out = NULL; } +#endif return; } diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 169c0e1525..ca838c33b0 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -225,6 +225,20 @@ ivas_error ivas_spat_hSpatParamRendCom_config( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC meta\n" ) ); } +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK + /* initialize buffers in handle with NULL - this handle is also used by other DirAC technologies, and not every technology is initializing all buffers */ + hSpatParamRendCom->azimuth = NULL; + hSpatParamRendCom->elevation = NULL; + hSpatParamRendCom->azimuth2 = NULL; + hSpatParamRendCom->elevation2 = NULL; + hSpatParamRendCom->diffuseness_vector = NULL; + hSpatParamRendCom->energy_ratio1 = NULL; + hSpatParamRendCom->energy_ratio2 = NULL; + hSpatParamRendCom->spreadCoherence = NULL; + hSpatParamRendCom->spreadCoherence2 = NULL; + hSpatParamRendCom->surroundingCoherence = NULL; +#endif + *hSpatParamRendCom_out = hSpatParamRendCom; } -- GitLab