-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
use GCC with "-fsanitize=address" options, detected memory leaks #20803
Comments
Could you try this example? https://github.com/microsoft/onnxruntime-inference-examples/tree/main/c_cxx/fns_candy_style_transfer |
I tried the Build script
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 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 |
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:
Then use the newly built libruntime.so to replace the one you got from our release page. |
The code change you suggested for fns_candy_style_transfer is good. We should take it. |
Thanks a lot. I tried what you suggested locally, now I'm sure it was a false alarm. |
I rebuilt the code with address sanitizer on Ubuntu 22.04, the alert is gone. But when I copied the the newly built lib/libonnxruntime.so: undefined reference to `stat64@GLIBC_2.33'
lib/libonnxruntime.so: undefined reference to `dlclose@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `fstat@GLIBC_2.33'
lib/libonnxruntime.so: undefined reference to `dlerror@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `pthread_key_create@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `pthread_rwlock_unlock@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `pthread_setspecific@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `__libc_single_threaded@GLIBC_2.32'
lib/libonnxruntime.so: undefined reference to `pthread_join@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `pthread_rwlock_destroy@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `pthread_rwlock_wrlock@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `dlsym@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `std::__throw_bad_array_new_length()@GLIBCXX_3.4.29'
lib/libonnxruntime.so: undefined reference to `pthread_attr_setstacksize@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `pthread_rwlock_init@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `stat@GLIBC_2.33'
lib/libonnxruntime.so: undefined reference to `dlopen@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `pthread_setaffinity_np@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `pthread_once@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `pthread_rwlock_rdlock@GLIBC_2.34'
lib/libonnxruntime.so: undefined reference to `pthread_create@GLIBC_2.34' The one I got from the release page |
This is normal. You may build it on Ubuntu 20.04 then ship it to Ubuntu 22.04, but not vice versa. |
Describe the issue
This is my code
Urgency
No response
Target platform
Ubuntu 22.04
Build script
gcc -g test.c -o inference -fsanitize=address -I../include -L../lib -lonnxruntime -Wl,-rpath=../lib
Error / output
Even if I use the new version, this problem still happens:
According to the call stack of the function, it seems that the memory leakage occurs in the ort_api->Run() function.
Which confuses me is that I can't see the exact memory leak location from the error.
Visual Studio Version
No response
GCC / Compiler Version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
The text was updated successfully, but these errors were encountered: