From f5a665bae2c156b73e03e8039b0b03dbb04df4a2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 30 Apr 2026 10:59:04 +0200 Subject: [PATCH 1/5] FIX_1585_ASAN_FORMAT_SW --- lib_com/options.h | 1 + lib_dec/lib_dec.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index d573f1393..f91cf9c15 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -184,6 +184,7 @@ #define FIX_FMSW_DEC_2 /* float issue 1575: fix crash for format switching when bitsream starts with EVS */ #define FIX_1548_HARMONIZE_NON_DIEGETIC_PANNING_LAW /* Orange: float issue 1548: Harmonize non diegetic panning law in ISM and renderers */ #define FIX_FLOAT_1578_OMASA_REND_SPIKES /* Nokia: Float issue 1578: Fix spikes and collapsed perception in OMASA/MASA rendering to FOA/HOA */ +#define FIX_1585_ASAN_FORMAT_SW /* VA: float issue 1585: fix memory leaks with format switching */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 63f78a949..55a94f4d8 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -397,6 +397,11 @@ ivas_error IVAS_DEC_Restart( #endif hIvasDec->mode = mode; +#ifdef FIX_1585_ASAN_FORMAT_SW + /* set 'ivas_format' to the last one to properly close IVAS decoder handles */ + hIvasDec->st_ivas->ivas_format = hIvasDec->st_ivas->last_ivas_format; +#endif + /* destroy Split binaural renderer (ISAR) handle */ ivas_destroy_handle_isar( &hIvasDec->st_ivas->hSplitBinRend ); -- GitLab From 26573750cc8563896fca0c7f0e56454472ce2fb2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 30 Apr 2026 11:02:14 +0200 Subject: [PATCH 2/5] move the switch FIX_1585_ASAN_FORMAT_SW --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index f91cf9c15..adb172428 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -165,6 +165,7 @@ #define FIX_FLOAT_1560_SVD_NO_OPT_MAX_W_SIGN /* FhG: float issue 1560: Avoid optimizing the division on the result of maxWithSign() with -funsafe-math-optimizations */ #define FIX_2095_REMOVE_UNUSED_ISAR_TABLES /* Dolby: remove unused ISAR */ #define FIX_FLOAT_1582_STEREO_DFT_QUANTIZE_ITD /* FhG: float issue 1582: Remove unncessary statement from stereo_dft_quantize_itd() */ +#define FIX_1585_ASAN_FORMAT_SW /* VA: float issue 1585: fix memory leaks with format switching */ /* #################### End BE switches ################################## */ @@ -184,7 +185,6 @@ #define FIX_FMSW_DEC_2 /* float issue 1575: fix crash for format switching when bitsream starts with EVS */ #define FIX_1548_HARMONIZE_NON_DIEGETIC_PANNING_LAW /* Orange: float issue 1548: Harmonize non diegetic panning law in ISM and renderers */ #define FIX_FLOAT_1578_OMASA_REND_SPIKES /* Nokia: Float issue 1578: Fix spikes and collapsed perception in OMASA/MASA rendering to FOA/HOA */ -#define FIX_1585_ASAN_FORMAT_SW /* VA: float issue 1585: fix memory leaks with format switching */ /* ##################### End NON-BE switches ########################### */ -- GitLab From 6e811bd56b8bda122220fc793ddc87915c2aa501 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 30 Apr 2026 13:07:42 +0200 Subject: [PATCH 3/5] FIX_1585_ASAN_FORMAT_SW_ALT --- lib_com/options.h | 2 ++ lib_dec/ivas_corecoder_dec_reconfig.c | 24 ++++++++++++++++++++++++ lib_dec/ivas_init_dec.c | 23 ++++++++++++++++++++++- lib_dec/ivas_stat_dec.h | 4 ++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index adb172428..609a5e412 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -166,6 +166,8 @@ #define FIX_2095_REMOVE_UNUSED_ISAR_TABLES /* Dolby: remove unused ISAR */ #define FIX_FLOAT_1582_STEREO_DFT_QUANTIZE_ITD /* FhG: float issue 1582: Remove unncessary statement from stereo_dft_quantize_itd() */ #define FIX_1585_ASAN_FORMAT_SW /* VA: float issue 1585: fix memory leaks with format switching */ +#define FIX_1585_ASAN_FORMAT_SW_ALT /* VA: float issue 1585: alternative fix memory leaks with format switching */ + /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index b66b8c54a..a8ef4a43c 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -381,7 +381,9 @@ ivas_error ivas_hp20_dec_reconfig( ) { int16_t i, nchan_hp20; +#ifndef FIX_1585_ASAN_FORMAT_SW_ALT float **old_mem_hp20_out; +#endif ivas_error error; error = IVAS_ERR_OK; @@ -394,6 +396,18 @@ ivas_error ivas_hp20_dec_reconfig( if ( nchan_hp20 > nchan_hp20_old ) { +#ifdef FIX_1585_ASAN_FORMAT_SW_ALT + /* create additional hp20 memories */ + for ( i = nchan_hp20_old; i < nchan_hp20; i++ ) + { + if ( ( st_ivas->mem_hp20_out[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM ); + } +#else /* save old mem_hp_20 pointer */ old_mem_hp20_out = st_ivas->mem_hp20_out; st_ivas->mem_hp20_out = NULL; @@ -421,9 +435,18 @@ ivas_error ivas_hp20_dec_reconfig( free( old_mem_hp20_out ); old_mem_hp20_out = NULL; +#endif } else if ( nchan_hp20 < nchan_hp20_old ) { +#ifdef FIX_1585_ASAN_FORMAT_SW_ALT + /* remove superfluous hp20 memories */ + for ( i = nchan_hp20; i < nchan_hp20_old; i++ ) + { + free( st_ivas->mem_hp20_out[i] ); + st_ivas->mem_hp20_out[i] = NULL; + } +#else /* save old mem_hp_20 pointer */ old_mem_hp20_out = st_ivas->mem_hp20_out; st_ivas->mem_hp20_out = NULL; @@ -447,6 +470,7 @@ ivas_error ivas_hp20_dec_reconfig( free( old_mem_hp20_out ); old_mem_hp20_out = NULL; +#endif } return error; diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 6e117aeae..7eda0e648 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2304,6 +2304,7 @@ ivas_error ivas_init_decoder( /* set number of output channels used for synthesis/decoding */ n = getNumChanSynthesis( st_ivas ); +#ifndef FIX_1585_ASAN_FORMAT_SW_ALT if ( n > 0 ) { if ( ( st_ivas->mem_hp20_out = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) @@ -2315,7 +2316,7 @@ ivas_error ivas_init_decoder( { st_ivas->mem_hp20_out = NULL; } - +#endif for ( i = 0; i < n; i++ ) { if ( ( st_ivas->mem_hp20_out[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) @@ -2326,6 +2327,13 @@ ivas_error ivas_init_decoder( set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM ); } +#ifdef FIX_1585_ASAN_FORMAT_SW_ALT + for ( ; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) + { + st_ivas->mem_hp20_out[i] = NULL; + } +#endif + /*-------------------------------------------------------------------* * Allocate and initialize rendering handles *--------------------------------------------------------------------*/ @@ -2822,7 +2830,9 @@ void ivas_initialize_handles_dec( #ifdef FIX_FMSW_DEC } #endif +#ifndef FIX_1585_ASAN_FORMAT_SW_ALT st_ivas->mem_hp20_out = NULL; +#endif st_ivas->hLimiter = NULL; /* ISM metadata handles */ @@ -2964,6 +2974,16 @@ void ivas_destroy_dec( } /* HP20 filter handles */ +#ifdef FIX_1585_ASAN_FORMAT_SW_ALT + for ( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) + { + if( st_ivas->mem_hp20_out[i] != NULL ) + { + free( st_ivas->mem_hp20_out[i] ); + st_ivas->mem_hp20_out[i] = NULL; + } + } +#else if ( st_ivas->mem_hp20_out != NULL ) { for ( i = 0; i < getNumChanSynthesis( st_ivas ); i++ ) @@ -2974,6 +2994,7 @@ void ivas_destroy_dec( free( st_ivas->mem_hp20_out ); st_ivas->mem_hp20_out = NULL; } +#endif /* ISM metadata handles */ ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 577b56450..18611feb9 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1054,7 +1054,11 @@ typedef struct Decoder_Struct uint16_t *bit_stream; /* Pointer to bitstream buffer */ int16_t writeFECoffset; /* parameter for debugging JBM stuff */ +#ifdef FIX_1585_ASAN_FORMAT_SW_ALT + float *mem_hp20_out[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; /* output signals HP filter memories */ +#else float **mem_hp20_out; /* output signals HP filter memories */ +#endif IVAS_LIMITER_HANDLE hLimiter; /* Limiter handle */ /* core-decoder modules */ -- GitLab From e0bbbdc5459966fd9d1c3e69ede300fa19b5c014 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 30 Apr 2026 13:10:28 +0200 Subject: [PATCH 4/5] clang-format --- lib_dec/ivas_init_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 7eda0e648..c3c3252aa 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2977,7 +2977,7 @@ void ivas_destroy_dec( #ifdef FIX_1585_ASAN_FORMAT_SW_ALT for ( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) { - if( st_ivas->mem_hp20_out[i] != NULL ) + if ( st_ivas->mem_hp20_out[i] != NULL ) { free( st_ivas->mem_hp20_out[i] ); st_ivas->mem_hp20_out[i] = NULL; -- GitLab From b4dd3f87bba009a34c4cbf04cb49e70aab8609d3 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 30 Apr 2026 15:18:40 +0200 Subject: [PATCH 5/5] remove FIX_1585_ASAN_FORMAT_SW --- lib_com/options.h | 1 - lib_dec/lib_dec.c | 5 ----- 2 files changed, 6 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 1851253ea..ef31d7758 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -165,7 +165,6 @@ #define FIX_FLOAT_1560_SVD_NO_OPT_MAX_W_SIGN /* FhG: float issue 1560: Avoid optimizing the division on the result of maxWithSign() with -funsafe-math-optimizations */ #define FIX_2095_REMOVE_UNUSED_ISAR_TABLES /* Dolby: remove unused ISAR */ #define FIX_FLOAT_1582_STEREO_DFT_QUANTIZE_ITD /* FhG: float issue 1582: Remove unncessary statement from stereo_dft_quantize_itd() */ -#define FIX_1585_ASAN_FORMAT_SW /* VA: float issue 1585: fix memory leaks with format switching */ #define FIX_1585_ASAN_FORMAT_SW_ALT /* VA: float issue 1585: alternative fix memory leaks with format switching */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 55a94f4d8..63f78a949 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -397,11 +397,6 @@ ivas_error IVAS_DEC_Restart( #endif hIvasDec->mode = mode; -#ifdef FIX_1585_ASAN_FORMAT_SW - /* set 'ivas_format' to the last one to properly close IVAS decoder handles */ - hIvasDec->st_ivas->ivas_format = hIvasDec->st_ivas->last_ivas_format; -#endif - /* destroy Split binaural renderer (ISAR) handle */ ivas_destroy_handle_isar( &hIvasDec->st_ivas->hSplitBinRend ); -- GitLab