如何使用Leak Sanitizer查找内存泄漏的原因 [英] How to find reason of memory leak with Leak Sanitizer

查看:1124
本文介绍了如何使用Leak Sanitizer查找内存泄漏的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用tbb的C ++程序,我正在使用GCC 6.2.1在64位Linux上进行编译。
当我使用address sanitizer(-fsanitize = address)进行编译并运行单元测试时,将生成以下输出:

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

使用关闭优化(-O0)和-fno-omit-frame-pointer编译代码。我如何获得有关泄漏的更多信息?

The code is compiled with optimizations turned off (-O0) and -fno-omit-frame-pointer. How could I get more information about the leak?

推荐答案

泄漏发生在系统库中,该系统库在未使用<$ c $进行编译的情况下c> -fno-omit-frame-pointer ,因此Asan无法使用帧指针对其进行放松。您可以通过设置

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.

顺便说一句,您可以要求LSan通过以下方式中止错误:

BTW you can ask LSan to not abort on error via

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

这篇关于如何使用Leak Sanitizer查找内存泄漏的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆