问题
I have a C++ program that uses tbb, I am compiling on 64bit Linux with GCC 6.2.1. When I compile with address sanitizer(-fsanitize=address) and run unit tests, this output is generated:
...
[ PASSED ] 56 tests.
=================================================================
==12326==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 54 byte(s) in 3 object(s) allocated from:
#0 0x7f4c634fd020 in strdup (/usr/lib64/libasan.so.3+0x58020)
#1 0x301d215bb4 (/usr/lib64/libtbb.so.2+0x301d215bb4)
SUMMARY: AddressSanitizer: 54 byte(s) leaked in 3 allocation(s).
make[3]: *** [CMakeFiles/check] Error 1
make[2]: *** [CMakeFiles/check.dir/all] Error 2
make[1]: *** [CMakeFiles/check.dir/rule] Error 2
make: *** [check] Error 2
The code is compiled with optimizations turned off (-O0) and -fno-omit-frame-pointer. How could I get more information about the leak?
回答1:
Leak happens in a system library which was presumably compiled without -fno-omit-frame-pointer
so Asan fails to unwind through it using frame pointers. You can try using slow but more robust DWARF unwinder by setting
# Or LSAN_OPTIONS, if you use standalone LSan
export ASAN_OPTIONS=fast_unwind_on_malloc=0
See here and here for more details about runtime flags.
BTW you can ask LSan to not abort on error via
# Or LSAN_OPTIONS, if you use standalone LSan
export ASAN_OPTIONS=exitcode=0:...
来源:https://stackoverflow.com/questions/46575977/how-to-find-reason-of-memory-leak-with-leak-sanitizer