Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in examples for C++ in your project. #457

Open
EjenY-Poltavchiny opened this issue Aug 11, 2024 · 2 comments
Open

Memory leak in examples for C++ in your project. #457

EjenY-Poltavchiny opened this issue Aug 11, 2024 · 2 comments

Comments

@EjenY-Poltavchiny
Copy link

Hi, there!
I've started to work with onnxruntime lib aproximately 2 mounth ago. I've tried to search for documentation for C++ and found some inferencing examples from ultralitycs and others (including your examples). After all i succesfuly run model inferencing and spent some time for postprocessing. However, I decided to check my code for memory leaks and other problems using clang sanitizer and found some memory leaks. After endless attempts to fix it, I still didn't understand why my code causes memory leaks, so i decided to check docs examples for memory leaks. And clang sanitizer found it:

==3972466==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7fc26e8d5a57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fc26e3b4df9  (/usr/local/lib/libonnxruntime.so.1.18.0+0xa2cdf9)

Direct leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7fc26e8d5a57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fc26e3b4ddd  (/usr/local/lib/libonnxruntime.so.1.18.0+0xa2cddd)

I've used this example.
This was my Cmake:

cmake_minimum_required(VERSION 3.5)

set(PROJECT_NAME Yolov8OnnxRuntimeCPPInference)
project(${PROJECT_NAME} VERSION 0.0.1 LANGUAGES CXX)

add_executable(Yolov8OnnxRuntimeCPPInference main.cpp)
target_link_libraries(Yolov8OnnxRuntimeCPPInference PRIVATE onnxruntime)

target_compile_options(Yolov8OnnxRuntimeCPPInference PRIVATE -fsanitize=address)
target_link_options(Yolov8OnnxRuntimeCPPInference PRIVATE -fsanitize=address)

Interesting fact - if i will run this code it will still cause memory leaks:

int main() {
  // onnxruntime setup
  Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "example-model-explorer");
  return 0;

Or this one:

int main() {
  // onnxruntime setup
  for (int i = 0; i < 10; ++i) {
    Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "example-model-explorer");
  }
  return 0;

They all will cause the same leak with no explainings (i've tried to find symbols by adress that sanitizer gives me, but it was no use)

==3991181==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7f353d9ffa57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f353d4dedf9  (/usr/local/lib/libonnxruntime.so.1.18.0+0xa2cdf9)

Direct leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7f353d9ffa57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f353d4deddd  (/usr/local/lib/libonnxruntime.so.1.18.0+0xa2cddd)

SUMMARY: AddressSanitizer: 256 byte(s) leaked in 2 allocation(s).
@tianleiwu
Copy link

@snnn, any idea of memory leak?

@snnn
Copy link
Member

snnn commented Aug 30, 2024

Might be a false alarm.
See: microsoft/onnxruntime#20803 (comment)

Please build the binary locally with symbols. Then run the example again. You will either see the "memory leak" is gone, or you will get a full stacktrace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants