From 210e203387cf46db7d2ba96bdcf55c91e51c88bb Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Wed, 11 Feb 2026 09:08:00 +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_fx.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 6f0d8e55e..91e82200a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -92,6 +92,7 @@ #define HARM_FD_BWE /* VA: harmonize core-coder FD BWE function duplications */ #define FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT /* FhG: basop issue 2411: harmonize TNSAnalysis*_fx(), DetectTnsFilt*_fx()*/ #define HARMONIZE_READ_DECODE_TNS /* FhG basop 2389: Harm between two pairs of functions. */ +#define FIX_FLOAT_1526_DIRAC_MEM_LEAK /* FhG: float issue 1526: potential memory leak in DirAC handles in case of format switching */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 6e6031712..d9c93caa7 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -3445,6 +3445,15 @@ void ivas_destroy_dec_fx( /* 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_fx( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); + + /* DirAC handles */ + ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); +#else /* DirAC handle */ IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { @@ -3456,6 +3465,7 @@ void ivas_destroy_dec_fx( ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); } +#endif /* SPAR handle */ ivas_spar_dec_close_fx( &( st_ivas->hSpar ), st_ivas->hDecoderConfig->output_Fs, 0 ); -- GitLab From 267d6056b87af65a15ae1c2afb92bde52d293f09 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Wed, 11 Feb 2026 13:48:16 +0100 Subject: [PATCH 2/2] properly initialize sub-handles/buffers with NULL, avoid depdency in free-functions from codec parameters --- lib_com/ivas_prot_fx.h | 6 +++++ lib_dec/ivas_init_dec_fx.c | 2 +- lib_dec/ivas_ism_dec_fx.c | 6 +++++ lib_dec/ivas_ism_param_dec_fx.c | 46 +++++++++++++++++++++++++++++++++ lib_rend/ivas_dirac_rend_fx.c | 14 ++++++++++ 5 files changed, 73 insertions(+), 1 deletion(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index ba65afec0..71f2e2be7 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -4127,11 +4127,17 @@ ivas_error ivas_param_ism_dec_open_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK +void ivas_param_ism_dec_close_fx( + PARAM_ISM_DEC_HANDLE *hParamIsmDec /* i/o: decoder ParamISM handle */ +); +#else void ivas_param_ism_dec_close_fx( 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_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index d9c93caa7..4a7cd31dc 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -3447,7 +3447,7 @@ void ivas_destroy_dec_fx( #ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK /* ParamISM dec handle */ - ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); + ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ) ); /* DirAC handles */ ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); diff --git a/lib_dec/ivas_ism_dec_fx.c b/lib_dec/ivas_ism_dec_fx.c index b087ab906..be53e67bd 100644 --- a/lib_dec/ivas_ism_dec_fx.c +++ b/lib_dec/ivas_ism_dec_fx.c @@ -168,7 +168,13 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) && EQ_32( last_ism_mode, ISM_MODE_PARAM ) ) { /* Deallocate the ParamISM struct */ +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK + ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ) ); + + ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); +#else ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); +#endif test(); IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) diff --git a/lib_dec/ivas_ism_param_dec_fx.c b/lib_dec/ivas_ism_param_dec_fx.c index 00c95d6dc..ff726c989 100644 --- a/lib_dec/ivas_ism_param_dec_fx.c +++ b/lib_dec/ivas_ism_param_dec_fx.c @@ -617,22 +617,55 @@ ivas_error ivas_param_ism_dec_open_fx( 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_fx = NULL; + hSpatParamRendCom->energy_ratio1_fx = NULL; + hSpatParamRendCom->energy_ratio2_fx = NULL; + hSpatParamRendCom->spreadCoherence_fx = NULL; + hSpatParamRendCom->spreadCoherence2_fx = NULL; + hSpatParamRendCom->surroundingCoherence_fx = 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_fx = NULL; + hParamIsmDec->hParamIsmRendering->interpolator_fx = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = NULL; + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = NULL; +#endif + output_Fs = st_ivas->hDecoderConfig->output_Fs; move32(); output_config = st_ivas->hDecoderConfig->output_config; @@ -838,11 +871,17 @@ ivas_error ivas_param_ism_dec_open_fx( * Close Param ISM handle *-------------------------------------------------------------------------*/ +#ifdef FIX_FLOAT_1526_DIRAC_MEM_LEAK +void ivas_param_ism_dec_close_fx( + PARAM_ISM_DEC_HANDLE *hParamIsmDec_out /* i/o: decoder DirAC handle */ +) +#else void ivas_param_ism_dec_close_fx( 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 { test(); IF( hParamIsmDec_out != NULL && *hParamIsmDec_out != NULL ) @@ -857,9 +896,11 @@ void ivas_param_ism_dec_close_fx( hParamIsmDec->hParamIsm = NULL; } +#ifndef FIX_FLOAT_1526_DIRAC_MEM_LEAK test(); IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { +#endif /* Param ISM Rendering */ IF( hParamIsmDec->hParamIsmRendering->interpolator_fx != NULL ) { @@ -871,7 +912,10 @@ void ivas_param_ism_dec_close_fx( free( hParamIsmDec->hParamIsmRendering->proto_matrix_fx ); hParamIsmDec->hParamIsmRendering->proto_matrix_fx = NULL; } +#ifndef FIX_FLOAT_1526_DIRAC_MEM_LEAK } +#endif + IF( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx != NULL ) { free( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx ); @@ -892,6 +936,7 @@ void ivas_param_ism_dec_close_fx( *hParamIsmDec_out = NULL; } +#ifndef FIX_FLOAT_1526_DIRAC_MEM_LEAK test(); IF( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL ) { @@ -906,6 +951,7 @@ void ivas_param_ism_dec_close_fx( free( *hSpatParamRendCom_out ); *hSpatParamRendCom_out = NULL; } +#endif return; } diff --git a/lib_rend/ivas_dirac_rend_fx.c b/lib_rend/ivas_dirac_rend_fx.c index 4ca7b0c14..cbd31bd13 100644 --- a/lib_rend/ivas_dirac_rend_fx.c +++ b/lib_rend/ivas_dirac_rend_fx.c @@ -226,6 +226,20 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( 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_fx = NULL; + hSpatParamRendCom->energy_ratio1_fx = NULL; + hSpatParamRendCom->energy_ratio2_fx = NULL; + hSpatParamRendCom->spreadCoherence_fx = NULL; + hSpatParamRendCom->spreadCoherence2_fx = NULL; + hSpatParamRendCom->surroundingCoherence_fx = NULL; +#endif + *hSpatParamRendCom_out = hSpatParamRendCom; } -- GitLab