Code not working with sanitizer turned on!

My application opens a connection with the following line:

int fd(v4l2_open(f_device_path.c_str(), O_RDWR));

A little later, I get a crash from the sanitizer that looks like this:

=================================================================
==14548==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0x007f8830ea10
    #0 0x7f931bf987 in operator delete(void*, unsigned long) (/usr/lib/aarch64-linux-gnu/libasan.so.4+0xd3987)
    #1 0x7f90810437 in __cxa_finalize (/lib/aarch64-linux-gnu/libc.so.6+0x35437)

0x007f8830ea10 is located 0 bytes inside of 40-byte region [0x007f8830ea10,0x007f8830ea38)
allocated by thread T0 here:
    #0 0x7f931bbb1b in malloc (/usr/lib/aarch64-linux-gnu/libasan.so.4+0xcfb1b)
    #1 0x7f86e6e833 in fnet::String::String(char const*) (/usr/lib/aarch64-linux-gnu/tegra/libnvfnet.so+0x7833)
    #2 0x7f93fafb37  (/lib/ld-linux-aarch64.so.1+0xdb37)
    #3 0x7f93fb3cd7  (/lib/ld-linux-aarch64.so.1+0x11cd7)
    #4 0x7f908e6693 in _dl_catch_exception (/lib/aarch64-linux-gnu/libc.so.6+0x10b693)
    #5 0x7f93fb3417  (/lib/ld-linux-aarch64.so.1+0x11417)
    #6 0x7f907c7013  (/lib/aarch64-linux-gnu/libdl.so.2+0x1013)
    #7 0x7f908e6693 in _dl_catch_exception (/lib/aarch64-linux-gnu/libc.so.6+0x10b693)
    #8 0x7f908e6737 in _dl_catch_error (/lib/aarch64-linux-gnu/libc.so.6+0x10b737)
    #9 0x7f907c877f  (/lib/aarch64-linux-gnu/libdl.so.2+0x277f)
    #10 0x7f907c70e7 in dlopen (/lib/aarch64-linux-gnu/libdl.so.2+0x10e7)
    #11 0x7f93138e83  (/usr/lib/aarch64-linux-gnu/libasan.so.4+0x4ce83)
    #12 0x7f916e8a67  (/usr/lib/aarch64-linux-gnu/tegra/libv4l2.so.0+0x7a67)
    #13 0x5588bce737 in video_connection::video_connection(std::shared_ptr<panel_context>, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/alexis/ve/virtual-entertainment/panel-ve/src/video_connection.cpp:111
    ...snip...

Would your fnet::String::~String() function use delete buffer instead of free(buffer);? (or maybe the constructor should use a new char[size] instead of malloc(), especially if you’re using a unique_ptr<> or auto_ptr<>).

I can still run my code, but that’s definitely something you want to fix in your next release.

Specifically, I use the following command line option to compile with the sanitizer:

g++ ... -fsanitize=address -fsanitize=enum -fsanitize=unreachable ...

Hi,
Do you use Jetpack 4.5.1(r32.5.1)? Please share your release version.

Is the following what you need?

$ jetson_release 
X Error of failed request:  BadLength (poly request too large or internal Xlib length error)
  Major opcode of failed request:  155 (NV-GLX)
  Minor opcode of failed request:  1 ()
  Serial number of failed request:  19
  Current serial number in output stream:  19
 - NVIDIA Jetson AGX Xavier [16GB]
   * Jetpack UNKNOWN [L4T 32.5.1]
   * NV Power Mode: MAXN - Type: 0
   * jetson_stats.service: active
 - Libraries:
   * CUDA: 10.2.89
   * cuDNN: 8.0.0.180
   * TensorRT: 7.1.3.0
   * Visionworks: 1.6.0.501
   * OpenCV: 4.1.1 compiled CUDA: NO
   * VPI: ii libnvvpi1 1.0.15 arm64 NVIDIA Vision Programming Interface library
   * Vulkan: 1.2.70

Hi,

For r32.5.1, please apply this prebuilt lib and give it a try:
Jetson/L4T/r32.5.x patches - eLinux.org
[camera] 3rdparty application fails to open with USB camera

It should resolve issues of opening v4l2 devices.