DPA lib Memory Leak Bug

Guys, I seem to encounter a memory leak problem when using DOCA DPA lib.

Here is my code:

class DpaKernel {
DpaKernel() {
...
        doca_dpa_create(dev->get_dev(), app, &dpa_ctx, flags);
}

~DpaKernel(){
        if (dpa_ctx != nullptr)
        {
            result= doca_dpa_destroy(dpa_ctx);
        }
}

}

And when I call the dealloc function of my class, the program fail to release flexio heap, the command line shows these error:

heap_destroy 317 - Failed to destroy heap, not all device heap memory was freed
flexio_process_destroy 907 - Failed to release prm heap memory
flexio_process_destroy 914 - Failed to destroy process PRM object (err = 22)

And LeakSanitizer detects the following memory leak stack info:

==1513557==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7fb37227ea57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fb3720eab02  (/lib/x86_64-linux-gnu/libmlx5.so.1+0x68b02)
    #2 0x7fb3721b39fe in flexio_create_prm_process ../libflexio/src/flexio_prm.c:252
    #3 0x7fb3721ac1c3 in process_create ../libflexio/src/flexio.c:689
    #4 0x7fb3721ac1c3 in flexio_process_create ../libflexio/src/flexio.c:845
    #5 0x7fb37218377e  (/opt/mellanox/doca/lib/x86_64-linux-gnu/libdoca_dpa.so.2+0x877e)
    #6 0x7fb37218621d in doca_dpa_create (/opt/mellanox/doca/lib/x86_64-linux-gnu/libdoca_dpa.so.2+0xb21d)
    #7 0x40fdab in dpu::DpaKernel::DpaKernel(std::shared_ptr<dpu::DpaDevice>&, doca_dpa_app*, unsigned int) /home/chengrx/dpa_bench/src/dpa/dpa_kernel.cc:12
    #8 0x421ed2 in test::DpaKernel_Launch_Test::TestBody() /home/chengrx/dpa_bench/test/dpa/test_dpa_kernel.cc:12
    #9 0x4c5397 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/chengrx/dpa_bench/deps/googletest/googletest/src/gtest.cc:2612
    #10 0x4b2e17 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/chengrx/dpa_bench/deps/googletest/googletest/src/gtest.cc:2648
    #11 0x459c25 in testing::Test::Run() /home/chengrx/dpa_bench/deps/googletest/googletest/src/gtest.cc:2687

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7fb37227ea57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fb3721a9c96 in heap_block_create ../libflexio/src/flexio_heap.c:55
    #2 0x7fb3721a9c96 in heap_malloc ../libflexio/src/flexio_heap.c:249
    #3 0x7fb3721b5dcf in flexio_buf_dev_alloc ../libflexio/src/flexio_mem.c:134
    #4 0x7fb3721b5dcf in flexio_buf_dev_alloc ../libflexio/src/flexio_mem.c:116
    #5 0x7fb3721b1e42 in internal_msg_stream_create ../libflexio/src/flexio_msg_stream.c:486
    #6 0x7fb3721b2c1d in flexio_msg_stream_create ../libflexio/src/flexio_msg_stream.c:797
    #7 0x7fb3721837e3  (/opt/mellanox/doca/lib/x86_64-linux-gnu/libdoca_dpa.so.2+0x87e3)
    #8 0x7fb37218621d in doca_dpa_create (/opt/mellanox/doca/lib/x86_64-linux-gnu/libdoca_dpa.so.2+0xb21d)
    #9 0x40fdab in dpu::DpaKernel::DpaKernel(std::shared_ptr<dpu::DpaDevice>&, doca_dpa_app*, unsigned int) /home/chengrx/dpa_bench/src/dpa/dpa_kernel.cc:12
    #10 0x421ed2 in test::DpaKernel_Launch_Test::TestBody() /home/chengrx/dpa_bench/test/dpa/test_dpa_kernel.cc:12
    #11 0x4c5397 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/chengrx/dpa_bench/deps/googletest/googletest/src/gtest.cc:2612
    #12 0x4b2e17 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/chengrx/dpa_bench/deps/googletest/googletest/src/gtest.cc:2648

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7fb37227ea57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fb3721a99d1 in heap_malloc_from_pool ../libflexio/src/flexio_heap.c:185
    #2 0x7fb3721a9e0b in heap_malloc ../libflexio/src/flexio_heap.c:264
    #3 0x7fb3721b5dcf in flexio_buf_dev_alloc ../libflexio/src/flexio_mem.c:134
    #4 0x7fb3721b5dcf in flexio_buf_dev_alloc ../libflexio/src/flexio_mem.c:116
    #5 0x7fb3721b1e42 in internal_msg_stream_create ../libflexio/src/flexio_msg_stream.c:486
    #6 0x7fb3721b2c1d in flexio_msg_stream_create ../libflexio/src/flexio_msg_stream.c:797
    #7 0x7fb3721837e3  (/opt/mellanox/doca/lib/x86_64-linux-gnu/libdoca_dpa.so.2+0x87e3)
    #8 0x7fb37218621d in doca_dpa_create (/opt/mellanox/doca/lib/x86_64-linux-gnu/libdoca_dpa.so.2+0xb21d)
    #9 0x40fdab in dpu::DpaKernel::DpaKernel(std::shared_ptr<dpu::DpaDevice>&, doca_dpa_app*, unsigned int) /home/chengrx/dpa_bench/src/dpa/dpa_kernel.cc:12
    #10 0x421ed2 in test::DpaKernel_Launch_Test::TestBody() /home/chengrx/dpa_bench/test/dpa/test_dpa_kernel.cc:12
    #11 0x4c5397 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/chengrx/dpa_bench/deps/googletest/googletest/src/gtest.cc:2612

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7fb37227ea57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fb3720eab02  (/lib/x86_64-linux-gnu/libmlx5.so.1+0x68b02)
    #2 0x7fb3721b3748 in flexio_create_prm_heap_mem ../libflexio/src/flexio_prm.c:179
    #3 0x7fb3721a9d5f in heap_block_create ../libflexio/src/flexio_heap.c:67
    #4 0x7fb3721a9d5f in heap_malloc ../libflexio/src/flexio_heap.c:249
    #5 0x7fb3721b5dcf in flexio_buf_dev_alloc ../libflexio/src/flexio_mem.c:134
    #6 0x7fb3721b5dcf in flexio_buf_dev_alloc ../libflexio/src/flexio_mem.c:116
    #7 0x7fb3721b1e42 in internal_msg_stream_create ../libflexio/src/flexio_msg_stream.c:486
    #8 0x7fb3721b2c1d in flexio_msg_stream_create ../libflexio/src/flexio_msg_stream.c:797
    #9 0x7fb3721837e3  (/opt/mellanox/doca/lib/x86_64-linux-gnu/libdoca_dpa.so.2+0x87e3)
    #10 0x7fb37218621d in doca_dpa_create (/opt/mellanox/doca/lib/x86_64-linux-gnu/libdoca_dpa.so.2+0xb21d)
    #11 0x40fdab in dpu::DpaKernel::DpaKernel(std::shared_ptr<dpu::DpaDevice>&, doca_dpa_app*, unsigned int) /home/chengrx/dpa_bench/src/dpa/dpa_kernel.cc:12
    #12 0x421ed2 in test::DpaKernel_Launch_Test::TestBody() /home/chengrx/dpa_bench/test/dpa/test_dpa_kernel.cc:12

It seems that, the bug is related to how doca_dpa_create and doca_dpa_destroy are implemented, and I have no way to see the codes. May I ask how to fix the memory leak bugs?

Thanks.

I think I found the solution, it seems dpa kernel must first release all its events before it actually call doca_dpa_destroy. After I rewrite the order of deallocation as such, the bug is fixed.

Thanks for sharing the solution!

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