Per*_*sta 3 c++ memory-leaks address-sanitizer
我有一个使用 tbb 的 C++ 程序,我正在使用 GCC 6.2.1 在 64 位 Linux 上进行编译。当我使用 address sanitizer(-fsanitize=address) 编译并运行单元测试时,会生成以下输出:
...
[ 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
Run Code Online (Sandbox Code Playgroud)
代码是在关闭优化 (-O0) 和 -fno-omit-frame-pointer 的情况下编译的。我如何获得有关泄漏的更多信息?
泄漏发生在一个系统库中,该库可能是在没有编译的情况下进行的,-fno-omit-frame-pointer因此 Asan 无法使用帧指针展开它。您可以通过设置尝试使用缓慢但更强大的 DWARF 展开器
# Or LSAN_OPTIONS, if you use standalone LSan
export ASAN_OPTIONS=fast_unwind_on_malloc=0
Run Code Online (Sandbox Code Playgroud)
顺便说一句,您可以通过以下方式要求 LSan 在错误时不中止
# Or LSAN_OPTIONS, if you use standalone LSan
export ASAN_OPTIONS=exitcode=0:...
Run Code Online (Sandbox Code Playgroud)