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/
    #1 0x7f90810437 in __cxa_finalize (/lib/aarch64-linux-gnu/

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/
    #1 0x7f86e6e833 in fnet::String::String(char const*) (/usr/lib/aarch64-linux-gnu/tegra/
    #2 0x7f93fafb37  (/lib/
    #3 0x7f93fb3cd7  (/lib/
    #4 0x7f908e6693 in _dl_catch_exception (/lib/aarch64-linux-gnu/
    #5 0x7f93fb3417  (/lib/
    #6 0x7f907c7013  (/lib/aarch64-linux-gnu/
    #7 0x7f908e6693 in _dl_catch_exception (/lib/aarch64-linux-gnu/
    #8 0x7f908e6737 in _dl_catch_error (/lib/aarch64-linux-gnu/
    #9 0x7f907c877f  (/lib/aarch64-linux-gnu/
    #10 0x7f907c70e7 in dlopen (/lib/aarch64-linux-gnu/
    #11 0x7f93138e83  (/usr/lib/aarch64-linux-gnu/
    #12 0x7f916e8a67  (/usr/lib/aarch64-linux-gnu/tegra/
    #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

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 ...

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:
   * TensorRT:
   * Visionworks:
   * OpenCV: 4.1.1 compiled CUDA: NO
   * VPI: ii libnvvpi1 1.0.15 arm64 NVIDIA Vision Programming Interface library
   * Vulkan: 1.2.70


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

It should resolve issues of opening v4l2 devices.