gpt4 book ai didi

c++ - 如何使用 Leak Sanitizer 查找内存泄漏的原因

转载 作者:太空狗 更新时间:2023-10-29 20:52:14 24 4
gpt4 key购买 nike

我有一个使用 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

代码是在关闭优化 (-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

参见 herehere有关运行时标志的更多详细信息。

顺便说一句,您可以通过以下方式要求 LSan 在发生错误时不要中止

# Or LSAN_OPTIONS, if you use standalone LSan
export ASAN_OPTIONS=exitcode=0:...

关于c++ - 如何使用 Leak Sanitizer 查找内存泄漏的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46575977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com