Comments (5)
I tried the fns_candy_style_transfer
example with -fsanitize=address
compile option, this example has three memory leaks
Build script
gcc -o fns_candy_style_transfer fns_candy_style_transfer.c image_file_libpng.c -fsanitize=address -Iinclude -Llib -lonnxruntime -lpng -Wl,-rpath=lib
Error / Output
./fns_candy_style_transfer candy.onnx test.png test2.png cpu
=================================================================
==3953065==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 1555200 byte(s) in 1 object(s) allocated from:
#0 0x7fc3bf15b887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
#1 0x556fe87576fb in chw_to_hwc (/home/gh/workspace/test/fns_candy_style_transfer/fns_candy_style_transfer+0x26fb)
#2 0x556fe8758712 in run_inference (/home/gh/workspace/test/fns_candy_style_transfer/fns_candy_style_transfer+0x3712)
#3 0x556fe875981e in main (/home/gh/workspace/test/fns_candy_style_transfer/fns_candy_style_transfer+0x481e)
#4 0x7fc3bdfd3d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
Direct leak of 1536 byte(s) in 1 object(s) allocated from:
#0 0x7fc3bf15ba57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x7fc3bec3adf9 (lib/libonnxruntime.so.1.18.0+0xa2cdf9)
Direct leak of 1536 byte(s) in 1 object(s) allocated from:
#0 0x7fc3bf15ba57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x7fc3bec3addd (lib/libonnxruntime.so.1.18.0+0xa2cddd)
SUMMARY: AddressSanitizer: 1558272 byte(s) leaked in 3 allocation(s).
The memory leaks at 0xa2cdf9
and 0xa2cddd
still exist.
The memory leak in the chw_to_hwc
function occurs because the variable output_data
is allocated using malloc
but is not freed after its use. The suggested solution is to manually release the allocated memory when it is no longer needed by freeing the memory pointed to by output_data
.
float* output_tensor_data = NULL;
ORT_ABORT_ON_ERROR(g_ort->GetTensorMutableData(output_tensor, (void**)&output_tensor_data));
uint8_t* output_image_data = NULL;
chw_to_hwc(output_tensor_data, 720, 720, &output_image_data);
if (write_image_file(output_image_data, 720, 720, output_file) != 0) {
ret = -1;
}
g_ort->ReleaseValue(output_tensor);
g_ort->ReleaseValue(input_tensor);
free(model_input);
free(output_image_data); // Manually release the memory when it is no longer needed
from onnxruntime.
It might be a false alarm. I rebuilt the code with address sanitizer, then the alert is gone. You may also try it locally. The command I used was:
python3 tools/ci_build/build.py --config Release --build_dir /tmp/cpubuild2 --parallel --skip_submodule_sync --enable_address_sanitizer --build_shared_lib
Then use the newly built libruntime.so to replace the one you got from our release page.
from onnxruntime.
The code change you suggested for fns_candy_style_transfer is good. We should take it.
from onnxruntime.
Could you try this example? https://github.com/microsoft/onnxruntime-inference-examples/tree/main/c_cxx/fns_candy_style_transfer
Does it have memory leak?
from onnxruntime.
It might be a false alarm. I rebuilt the code with address sanitizer, then the alert is gone. You may also try it locally. The command I used was:
python3 tools/ci_build/build.py --config Release --build_dir /tmp/cpubuild2 --parallel --skip_submodule_sync --enable_address_sanitizer --build_shared_lib
Then use the newly built libruntime.so to replace the one you got from our release page.
Thanks a lot. I tried what you suggested locally, now I'm sure it was a false alarm.
from onnxruntime.
Related Issues (20)
- Please Add webpack and typescript configuration HOT 2
- How to use I/O binding if input tensor shape is not fixed HOT 2
- [Build] wheels of 1.17/1.18 not found installing with uv HOT 3
- [Mobile] android prod crash: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) HOT 4
- [Feature Request] prebuilt package with cudnn 9 support HOT 6
- When will onnxruntime make it available to get nodeunit inputs correctly for QLinearConcat HOT 5
- [Build] support for CPython 3.13.0b1
- [Feature Request] why is `FunctionProto` missing from the file "onnxruntime/core/providers/shared_library/provider_wrappedtypes.h"? HOT 3
- [Build] Dockerfile.tensorrt out of date HOT 3
- [Web] I canβt use onnruntime-web to load a onnx model in a react web HOT 5
- Unauthorized for `onnxruntime-cuda-12/pypi/simple/`
- [Documentation] The documentation for early versions is missing HOT 2
- pip install failure for onnxruntime==1.17.3 HOT 1
- Index put loop model regression with ort==1.18
- Non-zero status code returned while running Add node. Name:'Add_221'
- can't install on Python HOT 1
- Error in quantize vicuna-7b model from fp16 to int8 HOT 4
- Issue of UNet Model Inference with [model.onnx + model.onnx_data] in ONNX Runtime C++ for Stable Diffusion HOT 9
- Gemm fp8 run error HOT 3
- Where is onnxruntime-openvino==1.18.0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from onnxruntime.