microsoft / microsoft/onnxruntime-inference-examples
Memory leak in examples for C++ in your project.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 414
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 14
Description
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).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with c_cxx/model-explorer/batch-model-explorer.cpp and reproduce the minimal Ort::Env cases using the provided CMake sanitizer flags. Compare the full example with the minimal program and inspect the reported allocations in the linked ONNX Runtime library. Done means the leak’s ownership is confirmed and the example or its documentation clearly addresses it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100