Skip to content

Memory leak in SBA to BINAURAL_ROOM_REVERB with memory instrumentation

Basic info

Bug description

When running the smoke test with the BASOP codec, a missing/invalid free is reported:

free(): invalid pointer

Valgrind reports:

==23349== Invalid free() / delete / delete[] / realloc()
==23349==    at 0x484B27F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==23349==    by 0x72ABAE: destroy_hrtf_statistics (hrtf_file_reader.c:2052)
==23349==    by 0x112A37: main (decoder.c:826)
==23349==  Address 0x4c2c0a4 is 4 bytes inside a block of size 524 alloc'd
==23349==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==23349==    by 0x74DDF2: mem_alloc_block (wmc_auto.c:1277)
==23349==    by 0x74DB6E: mem_alloc (wmc_auto.c:1195)
==23349==    by 0x13A72D: ivas_HRTF_statistics_init_fx (ivas_hrtf_fx.c:395)
==23349==    by 0x202BFD: ivas_init_decoder_fx (ivas_init_dec_fx.c:1897)
==23349==    by 0x201072: ivas_dec_setup (ivas_init_dec_fx.c:1229)
==23349==    by 0x126DF6: ivas_dec_setup_all (lib_dec_fx.c:2028)
==23349==    by 0x12BDD5: IVAS_DEC_GetSamplesDecoder (lib_dec_fx.c:4313)
==23349==    by 0x117AA5: decodeG192 (decoder.c:2586)
==23349==    by 0x112891: main (decoder.c:764)
==23349==
==23349== Invalid free() / delete / delete[] / realloc()
==23349==    at 0x484B27F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==23349==    by 0x72ABD1: destroy_hrtf_statistics (hrtf_file_reader.c:2056)
==23349==    by 0x112A37: main (decoder.c:826)
==23349==  Address 0x4c2c2f4 is 4 bytes inside a block of size 524 alloc'd
==23349==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==23349==    by 0x74DDF2: mem_alloc_block (wmc_auto.c:1277)
==23349==    by 0x74DB6E: mem_alloc (wmc_auto.c:1195)
==23349==    by 0x13A77A: ivas_HRTF_statistics_init_fx (ivas_hrtf_fx.c:400)
==23349==    by 0x202BFD: ivas_init_decoder_fx (ivas_init_dec_fx.c:1897)
==23349==    by 0x201072: ivas_dec_setup (ivas_init_dec_fx.c:1229)
==23349==    by 0x126DF6: ivas_dec_setup_all (lib_dec_fx.c:2028)
==23349==    by 0x12BDD5: IVAS_DEC_GetSamplesDecoder (lib_dec_fx.c:4313)
==23349==    by 0x117AA5: decodeG192 (decoder.c:2586)
==23349==    by 0x112891: main (decoder.c:764)
==23349==
==23349== Invalid free() / delete / delete[] / realloc()
==23349==    at 0x484B27F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==23349==    by 0x72ABF4: destroy_hrtf_statistics (hrtf_file_reader.c:2060)
==23349==    by 0x112A37: main (decoder.c:826)
==23349==  Address 0x4c2c544 is 4 bytes inside a block of size 524 alloc'd
==23349==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==23349==    by 0x74DDF2: mem_alloc_block (wmc_auto.c:1277)
==23349==    by 0x74DB6E: mem_alloc (wmc_auto.c:1195)
==23349==    by 0x13A7C7: ivas_HRTF_statistics_init_fx (ivas_hrtf_fx.c:405)
==23349==    by 0x202BFD: ivas_init_decoder_fx (ivas_init_dec_fx.c:1897)
==23349==    by 0x201072: ivas_dec_setup (ivas_init_dec_fx.c:1229)
==23349==    by 0x126DF6: ivas_dec_setup_all (lib_dec_fx.c:2028)
==23349==    by 0x12BDD5: IVAS_DEC_GetSamplesDecoder (lib_dec_fx.c:4313)
==23349==    by 0x117AA5: decodeG192 (decoder.c:2586)
==23349==    by 0x112891: main (decoder.c:764)
==23349==


 --- Complexity analysis [WMOPS] ---

                                           |------  SELF  ------|   |---  CUMULATIVE  ---|
                        routine    calls     min     max     avg      min     max     avg
                ---------------   ------   ------  ------  ------   ------  ------  ------
                ivas_jbm_dec_tc     1.00    1.093   1.096   1.096   21.063  22.478  21.712
               ivas_spar_decode     1.00    0.391   0.409   0.397    1.607   1.686   1.628
               ivas_spar_dec_MD     1.00    1.209   1.290   1.230    1.209   1.290   1.230
                   ivas_sce_dec     1.00    0.177   0.177   0.177   18.284  19.774  18.988
                  ivas_core_dec     1.00    2.932   5.695   5.388   18.107  19.597  18.811
                 acelp_core_dec     0.98   12.520  14.021  13.357   12.520  14.021  13.357
      ivas_dec_prepare_renderer     1.00    3.638   3.861   3.660    3.638   3.861   3.660
                ivas_dec_render     1.00   47.084  47.819  47.709   54.370  55.360  55.246
    ivas_sba_prototype_renderer     4.00    2.984   3.239   3.234    2.984   3.239   3.234
                binaural_reverb     4.00    4.302   4.302   4.302    4.302   4.302   4.302
            stereo_tcx_core_dec     0.02   16.665  16.665  16.665   16.665  16.665  16.665
                ---------------   ------   ------  ------  ------
                          total    50.00   79.153  81.429  80.618


Complexity analysis for the worst-case frame 22:

                        routine    calls       SELF   CUMULATIVE
                ---------------   ------     ------   ----------
                ivas_jbm_dec_tc        1      1.096       22.317
               ivas_spar_decode        1      0.394        1.622
               ivas_spar_dec_MD        1      1.228        1.228
                   ivas_sce_dec        1      0.177       19.599
                  ivas_core_dec        1      5.469       19.422
                 acelp_core_dec        1     13.953       13.953
      ivas_dec_prepare_renderer        1      3.764        3.764
                ivas_dec_render        1     47.807       55.348
    ivas_sba_prototype_renderer        4      3.239        3.239
                binaural_reverb        4      4.302        4.302

Call tree for the worst-case frame 22:

            function  num  called by
     ---------------  ---  --------------
     ivas_jbm_dec_tc    0
    ivas_spar_decode    1  0
    ivas_spar_dec_MD    2  1
        ivas_sce_dec    3  0
       ivas_core_dec    4  3
      acelp_core_dec    5  4
ivas_dec_prepare_renderer    6
     ivas_dec_render    7
ivas_sba_prototype_renderer    8  7
     binaural_reverb    9  7



Instruction type analysis for the worst-case frame 22:

	Adds:                   0.0
	Absolutes:              0.0
	Multiplies:             0.0
	MACs:                   0.0
	Moves:                  0.0
	Stores:                 0.0
	Logicals:               0.0
	Shifts:                 0.0
	Branches:               0.0
	Divisions:              0.0
	Square Root:            0.0
	Trans:                  0.0
	Func Call:              0.0
	Loop Init:              0.0
	Indirect Addr:          0.0
	Pointer Init:           0.0
	Extra condit.:          0.0
	Exponential:            0.0
	Logarithm:              0.0
	All other op.:          0.0


 --- Memory usage ---

Program ROM size: not available
Table ROM (const data) size: not available
Maximum RAM (stack + heap) size: 377558 bytes in frame 0
Maximum stack size: not available
Fct=ivas_HRTF_statistics_init_fx, Ln=395: Error: Memory Block has not been De-Allocated with free()!!
==23349==
==23349== HEAP SUMMARY:
==23349==     in use at exit: 403,552 bytes in 11 blocks
==23349==   total heap usage: 566 allocs, 558 frees, 2,250,740 bytes allocated
==23349==
==23349== 524 bytes in 1 blocks are possibly lost in loss record 2 of 11
==23349==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==23349==    by 0x74DDF2: mem_alloc_block (wmc_auto.c:1277)
==23349==    by 0x74DB6E: mem_alloc (wmc_auto.c:1195)
==23349==    by 0x13A72D: ivas_HRTF_statistics_init_fx (ivas_hrtf_fx.c:395)
==23349==    by 0x202BFD: ivas_init_decoder_fx (ivas_init_dec_fx.c:1897)
==23349==    by 0x201072: ivas_dec_setup (ivas_init_dec_fx.c:1229)
==23349==    by 0x126DF6: ivas_dec_setup_all (lib_dec_fx.c:2028)
==23349==    by 0x12BDD5: IVAS_DEC_GetSamplesDecoder (lib_dec_fx.c:4313)
==23349==    by 0x117AA5: decodeG192 (decoder.c:2586)
==23349==    by 0x112891: main (decoder.c:764)
==23349==
==23349== 524 bytes in 1 blocks are possibly lost in loss record 3 of 11
==23349==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==23349==    by 0x74DDF2: mem_alloc_block (wmc_auto.c:1277)
==23349==    by 0x74DB6E: mem_alloc (wmc_auto.c:1195)
==23349==    by 0x13A77A: ivas_HRTF_statistics_init_fx (ivas_hrtf_fx.c:400)
==23349==    by 0x202BFD: ivas_init_decoder_fx (ivas_init_dec_fx.c:1897)
==23349==    by 0x201072: ivas_dec_setup (ivas_init_dec_fx.c:1229)
==23349==    by 0x126DF6: ivas_dec_setup_all (lib_dec_fx.c:2028)
==23349==    by 0x12BDD5: IVAS_DEC_GetSamplesDecoder (lib_dec_fx.c:4313)
==23349==    by 0x117AA5: decodeG192 (decoder.c:2586)
==23349==    by 0x112891: main (decoder.c:764)
==23349==
==23349== 524 bytes in 1 blocks are possibly lost in loss record 4 of 11
==23349==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==23349==    by 0x74DDF2: mem_alloc_block (wmc_auto.c:1277)
==23349==    by 0x74DB6E: mem_alloc (wmc_auto.c:1195)
==23349==    by 0x13A7C7: ivas_HRTF_statistics_init_fx (ivas_hrtf_fx.c:405)
==23349==    by 0x202BFD: ivas_init_decoder_fx (ivas_init_dec_fx.c:1897)
==23349==    by 0x201072: ivas_dec_setup (ivas_init_dec_fx.c:1229)
==23349==    by 0x126DF6: ivas_dec_setup_all (lib_dec_fx.c:2028)
==23349==    by 0x12BDD5: IVAS_DEC_GetSamplesDecoder (lib_dec_fx.c:4313)
==23349==    by 0x117AA5: decodeG192 (decoder.c:2586)
==23349==    by 0x112891: main (decoder.c:764)
==23349==
==23349== LEAK SUMMARY:
==23349==    definitely lost: 0 bytes in 0 blocks
==23349==    indirectly lost: 0 bytes in 0 blocks
==23349==      possibly lost: 1,572 bytes in 3 blocks
==23349==    still reachable: 401,980 bytes in 8 blocks
==23349==         suppressed: 0 bytes in 0 blocks
==23349== Reachable blocks (those to which a pointer was found) are not shown.
==23349== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==23349==
==23349== For lists of detected and suppressed errors, rerun with: -s
==23349== ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 0 from 0)

Without the instrumentation, this does not happen. Also, I can not reproduce this on Mac, only on Linux.

Ways to reproduce

stvFOA48c_FOA_b13_2_wb_cbr.192

make clean
python3 scripts/prepare_mem_dryrun.py
sed -i.bak -e "s/\/\*\s*\(#define\s*WMOPS\)\s*\*\//\1/g" lib_com/options.h
sed -i.bak -e "s/\/\/\s*\(#define\s*WMOPS\)/\1/g" lib_com/options.h
make all -j
valgrind ./IVAS_dec BINAURAL_ROOM_REVERB 16 bit out.wav