Azure-Kinect-Sensor-SDK icon indicating copy to clipboard operation
Azure-Kinect-Sensor-SDK copied to clipboard

Azure Kinect Address Sanitizer Issue

Open foohyfooh opened this issue 4 years ago • 1 comments

When using the Azure Kinect SDK on branch release/1.3.x, I have found the following issues when compiling with Address Sanitizer -fsanitize=address

My CMakeLists.txt is as follows

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
add_executable(k4a_test test.cpp)
target_link_libraries(k4a_test PRIVATE k4a::k4a)

Error 1: libusb issue when using k4a_device_open

This issue doesn't happen consistently but it does happen frequently

Example Kinect Calls

k4a_device_t device = nullptr;
if (K4A_RESULT_SUCCEEDED != k4a_device_open(K4A_DEVICE_DEFAULT, &device))
{
  std::cout << "Failed to open device" << std::endl;
  return EXIT_FAILURE;
}
k4a_device_close(device);

Address Sanitizer Output

=================================================================
==27561==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 152 byte(s) in 1 object(s) allocated from:
    #0 0x7fdc2372313e in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10c13e)
    #1 0x7fdc233a4075 in usbi_alloc_device ../extern/libusb/src/libusb/core.c:677

Direct leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7fdc2372313e in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10c13e)
    #1 0x7fdc233ab952 in submit_bulk_transfer ../extern/libusb/src/libusb/os/linux_usbfs.c:1934

Indirect leak of 3072 byte(s) in 3 object(s) allocated from:
    #0 0x7fdc2372337e in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10c37e)
    #1 0x7fdc233aea7d in usbi_reallocf ../extern/libusb/src/libusb/libusbi.h:171
    #2 0x7fdc233aea7d in initialize_device ../extern/libusb/src/libusb/os/linux_usbfs.c:991
    #3 0x7fdc233aea7d in linux_enumerate_device ../extern/libusb/src/libusb/os/linux_usbfs.c:1146

Indirect leak of 304 byte(s) in 2 object(s) allocated from:
    #0 0x7fdc2372313e in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10c13e)
    #1 0x7fdc233a4075 in usbi_alloc_device ../extern/libusb/src/libusb/core.c:677

Indirect leak of 15 byte(s) in 3 object(s) allocated from:
    #0 0x7fdc236abccd in __interceptor_strdup (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x94ccd)
    #1 0x7fdc233ae9b0 in initialize_device ../extern/libusb/src/libusb/os/linux_usbfs.c:961
    #2 0x7fdc233ae9b0 in linux_enumerate_device ../extern/libusb/src/libusb/os/linux_usbfs.c:1146

SUMMARY: AddressSanitizer: 3599 byte(s) leaked in 10 allocation(s).

Logs

error1.log

Error 2: Issue when creating transformation using k4a_transformation_create

When src/sdk/k4a.c has TRANSFORM_ENABLE_GPU_OPTIMIZATION defined as true, it would give the below issues but if TRANSFORM_ENABLE_GPU_OPTIMIZATION is defined as false, the issue will not occur

Example Program

k4a_device_t device = nullptr;
if (K4A_RESULT_SUCCEEDED != k4a_device_open(K4A_DEVICE_DEFAULT, &device))
{
    std::cout << "Failed to open device" << std::endl;
    return EXIT_FAILURE;
}

k4a_calibration_t calibration;

k4a_device_configuration_t deviceConfig = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;
deviceConfig.color_format = K4A_IMAGE_FORMAT_COLOR_MJPG;
deviceConfig.color_resolution = K4A_COLOR_RESOLUTION_720P;
deviceConfig.depth_mode = K4A_DEPTH_MODE_WFOV_UNBINNED;
deviceConfig.camera_fps = K4A_FRAMES_PER_SECOND_15;
deviceConfig.wired_sync_mode = K4A_WIRED_SYNC_MODE_STANDALONE;
deviceConfig.synchronized_images_only = true;

if (K4A_RESULT_SUCCEEDED !=
    k4a_device_get_calibration(device, deviceConfig.depth_mode, deviceConfig.color_resolution, &calibration))
{
    std::cout << "Failed to get calibration" << std::endl;
    k4a_device_close(device);
    return EXIT_FAILURE;
}

k4a_device_close(device);

k4a_transformation_t transformation = k4a_transformation_create(&calibration);
k4a_transformation_destroy(transformation);

Address Sanitizer Output

=================================================================
==27216==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 6280 byte(s) in 3 object(s) allocated from:
    #0 0x7fbc4ad8a13e in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10c13e)
    #1 0x7fbc40c8f995  (/usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.435.21+0xe39995)

Direct leak of 512 byte(s) in 1 object(s) allocated from:
    #0 0x7fbc4ad8a37e in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10c37e)
    #1 0x7fbc40c8f28f  (/usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.435.21+0xe3928f)

Indirect leak of 72672 byte(s) in 224 object(s) allocated from:
    #0 0x7fbc4ad8a13e in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10c13e)
    #1 0x7fbc40c8f995  (/usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.435.21+0xe39995)

Indirect leak of 2528 byte(s) in 179 object(s) allocated from:
    #0 0x7fbc4ad89f48 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10bf48)
    #1 0x7fbc40c8fb5b  (/usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.435.21+0xe39b5b)

Indirect leak of 752 byte(s) in 6 object(s) allocated from:
    #0 0x7fbc4ad8a37e in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10c37e)
    #1 0x7fbc40c8f28f  (/usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.435.21+0xe3928f)

SUMMARY: AddressSanitizer: 82744 byte(s) leaked in 413 allocation(s).

Logs

error2.log

Desktop Information

  • OS with Version: Linux Desktop 4.15.0-70-generic 79-Ubuntu SMP Tue Nov 12 10:36:11 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • SDK Version:
    • branch: releases/1.3.x
    • hash: 17b644560ce7b4ee7dd921dfff0ae811aa54ede6
  • Firmware version:
    • Current Firmware Versions:
    • RGB camera firmware: 1.6.102
    • Depth camera firmware: 1.6.75
    • Depth config file: 6109.7
    • Audio firmware: 1.6.14
    • Build Config: Production
    • Certificate Type: Microsoft
  • NVIDIA Driver Version: 435.21

Edit Note: Added missing summary line for error 2

foohyfooh avatar Feb 13 '20 20:02 foohyfooh

Not sure we will be able to fix the libusb issue, but we will take a look

wes-b avatar Feb 20 '20 19:02 wes-b