Alloc-dealloc-mismatch after v4l2_open in Jetpack 5

It seems that there is a bug in libnvfnet–if you compile the 00_video_decode sample with AddressSanitizer (add CC=clang CPP=clang++ CFLAGS+=-fsanitize=address CPPFLAGS+=-fsanitize=address to Rules.mk) you get the following error:

./video_decode H264 ~/sky.h264
Set governor to performance before enabling profiler
Creating decoder in blocking mode
=================================================================
==8942==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0xffffb5a03450
    #0 0x4bee24 in operator delete(void*, unsigned long) (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4bee24)
    #1 0xffffba3c3ab4 in __cxa_finalize /build/glibc-RIFKjK/glibc-2.31/stdlib/cxa_finalize.c:83:6
    #2 0xffffb4d5c68c  (/usr/lib/aarch64-linux-gnu/tegra/libnvfnet.so+0x768c)
    #3 0xffffbd96ef14 in call_destructors /build/glibc-RIFKjK/glibc-2.31/elf/dl-close.c:125:3
    #4 0xffffba497078 in _dl_catch_exception /build/glibc-RIFKjK/glibc-2.31/elf/dl-error-skeleton.c:182:7
    #5 0xffffbd96f4fc in _dl_close_worker /build/glibc-RIFKjK/glibc-2.31/elf/dl-close.c:297:3
    #6 0xffffbd96f4fc in _dl_close_worker /build/glibc-RIFKjK/glibc-2.31/elf/dl-close.c:135:1
    #7 0xffffbd97001c in _dl_close /build/glibc-RIFKjK/glibc-2.31/elf/dl-close.c:859:3
    #8 0xffffba497018 in _dl_catch_exception /build/glibc-RIFKjK/glibc-2.31/elf/dl-error-skeleton.c:208:8
    #9 0xffffba4970e4 in _dl_catch_error /build/glibc-RIFKjK/glibc-2.31/elf/dl-error-skeleton.c:227:19
    #10 0xffffba525834 in _dlerror_run /build/glibc-RIFKjK/glibc-2.31/dlfcn/dlerror.c:170:21
    #11 0xffffba5251cc in dlclose /build/glibc-RIFKjK/glibc-2.31/dlfcn/dlclose.c:46:10
    #12 0x46d6e8 in dlclose (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x46d6e8)
    #13 0xffffbd7f7a10  (/lib/aarch64-linux-gnu/libv4l2.so.0+0x8a10)
    #14 0xffffbd7f226c in v4l2_fd_open (/lib/aarch64-linux-gnu/libv4l2.so.0+0x326c)
    #15 0xffffbd7f299c in v4l2_open (/lib/aarch64-linux-gnu/libv4l2.so.0+0x399c)
    #16 0x581cc4 in NvV4l2Element::NvV4l2Element(char const*, char const*, int, int) (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x581cc4)
    #17 0x4defc4 in NvVideoDecoder::NvVideoDecoder(char const*, int) (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4defc4)
    #18 0x4df03c in NvVideoDecoder::createVideoDecoder(char const*, int) (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4df03c)
    #19 0x4c3eb0 in decode_proc(context_t&, int, char**) (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4c3eb0)
    #20 0x4c39fc in main (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4c39fc)
    #21 0xffffba3ade0c in __libc_start_main /build/glibc-RIFKjK/glibc-2.31/csu/../csu/libc-start.c:308:16
    #22 0x4258a0 in _start (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4258a0)

0xffffb5a03450 is located 0 bytes inside of 40-byte region [0xffffb5a03450,0xffffb5a03478)
allocated by thread T0 (DecOutPlane) here:
    #0 0x492744 in malloc (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x492744)
    #1 0xffffb4d5cd48 in fnet::String::String(char const*) (/usr/lib/aarch64-linux-gnu/tegra/libnvfnet.so+0x7d48)
    #2 0xffffbd96a9b0 in call_init /build/glibc-RIFKjK/glibc-2.31/elf/dl-init.c:30:6
    #3 0xffffbd96a9b0 in _dl_init /build/glibc-RIFKjK/glibc-2.31/elf/dl-init.c:119:5
    #4 0xffffba497078 in _dl_catch_exception /build/glibc-RIFKjK/glibc-2.31/elf/dl-error-skeleton.c:182:7
    #5 0xffffbd96ea10 in dl_open_worker /build/glibc-RIFKjK/glibc-2.31/elf/dl-open.c:758:5
    #6 0xffffba497018 in _dl_catch_exception /build/glibc-RIFKjK/glibc-2.31/elf/dl-error-skeleton.c:208:8
    #7 0xffffbd96e1a0 in _dl_open /build/glibc-RIFKjK/glibc-2.31/elf/dl-open.c:837:17
    #8 0xffffba525098 in dlopen_doit /build/glibc-RIFKjK/glibc-2.31/dlfcn/dlopen.c:66:15
    #9 0xffffba497018 in _dl_catch_exception /build/glibc-RIFKjK/glibc-2.31/elf/dl-error-skeleton.c:208:8
    #10 0xffffba4970e4 in _dl_catch_error /build/glibc-RIFKjK/glibc-2.31/elf/dl-error-skeleton.c:227:19
    #11 0xffffba525834 in _dlerror_run /build/glibc-RIFKjK/glibc-2.31/dlfcn/dlerror.c:170:21
    #12 0xffffba52513c in dlopen /build/glibc-RIFKjK/glibc-2.31/dlfcn/dlopen.c:87:10
    #13 0x46d668 in dlopen (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x46d668)
    #14 0xffffbd7f7a58  (/lib/aarch64-linux-gnu/libv4l2.so.0+0x8a58)
    #15 0x4defc4 in NvVideoDecoder::NvVideoDecoder(char const*, int) (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4defc4)
    #16 0x4df03c in NvVideoDecoder::createVideoDecoder(char const*, int) (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4df03c)
    #17 0x4c3eb0 in decode_proc(context_t&, int, char**) (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4c3eb0)
    #18 0x4c39fc in main (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4c39fc)
    #19 0xffffba3ade0c in __libc_start_main /build/glibc-RIFKjK/glibc-2.31/csu/../csu/libc-start.c:308:16
    #20 0x4258a0 in _start (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4258a0)

SUMMARY: AddressSanitizer: alloc-dealloc-mismatch (/home/russell/jetson_multimedia_api/samples/00_video_decode/video_decode+0x4bee24) in operator delete(void*, unsigned long)
==8942==HINT: if you don't care about these errors you may set ASAN_OPTIONS=alloc_dealloc_mismatch=0
==8942==ABORTING

The hack suggested in Memory Leak (Alloc/free mismatch) in Tegra multimedia API (encoder) - #6 by DaneLLL does indeed work, but considering that was over a year ago and this is a later release, clearly the bug was not fixed. I do not think renaming that file is an acceptable fix.

System info: Jetpack 5.0.2 with BSP 35.1 AGX Xavier

Hi,
We are still working on it. On Jetpack 5, nvarguscamerasrc is still in-use and it is not obligatory to load libv4l2_nvargus.so, so the quick fix is fine. Please rename it so that the lib will not be loaded.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.