How to find reason of memory leak with Leak Sanitizer

走远了吗. 提交于 2020-01-14 14:27:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!