简体   繁体   中英

How to find reason of memory leak with Leak Sanitizer

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?

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 andhere 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:...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM