LeakSanitizer和泄漏的库 [英] LeakSanitizer and leaky libraries

查看:185
本文介绍了LeakSanitizer和泄漏的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用gcc的泄漏消毒剂选项来检测程序中的泄漏.

I am trying to use gcc's leak sanitizer option to detect leaks in my program.

为此,我使用相关标志进行编译,运行我的程序,然后终止,这将导致以下输出:

For this I compile with the rlevant flags, run my program, then terminate, which results in the following output:

==8013==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 72704 byte(s) in 1 object(s) allocated from:
    #0 0x7f3ace944ada in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f3ab2f8690d  (<unknown module>)
    #2 0x7f3ab2f50525  (<unknown module>)

Direct leak of 72704 byte(s) in 1 object(s) allocated from:
    #0 0x7f3ace944ada in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f3ab51d2aad  (<unknown module>)
    #2 0x7f3ab51c4475  (<unknown module>)

Direct leak of 256 byte(s) in 1 object(s) allocated from:
    #0 0x7f3ace944ada in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x562db822861c in RenderHandler::RenderHandler() ../Src/main.cpp:68
    #2 0x562db8226ee2 in main ../Src/main.cpp:200
    #3 0x7f3acdf61ee2 in __libc_start_main (/usr/lib/libc.so.6+0x26ee2)

Direct leak of 232 byte(s) in 5 object(s) allocated from:
    #0 0x7f3ace944ada in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f3ab3e31677  (<unknown module>)
[...]

据我所知,许多库(甚至是标准库)都可能有泄漏的代码,对此我并不十分担心.如果我的视频驱动程序代码泄漏,我将不修复它.

From what I have been told, many libraries (even the standard libraries) can have leaky code, which I am not terribly worried about. If my video driver has leaky code, I am not going to fix that.

但是,在上述堆栈跟踪中,存在一个相关的泄漏(报告了第三处).我故意添加的那个.

However in the above stack trace there is one relevant leak (third one reported). That one I added on purpose.

我不想打印未知模块"中发生的任何泄漏,因为我无法修复在我不知道的地方(这些泄漏可能来自第三方库)中发生的泄漏,并且它们有一个倾向于隐藏我实际上可以解决的漏洞.

I want to not print any leaks that happen in "unkown modules" since I can't fix a leak that occurs in a place I don't know (these are likely coming from third party libraries), and they have a tendency to hide the leaks I can actually fix.

是否有一种指示泄漏消毒剂的机制来避免打印某些类型的泄漏?

Is there a mechanism to instruct leak sanitizer to avoid printing certain kinds of leaks?

推荐答案

使用抑制文件,如 AddressSanitizerLeakSanitizer#suppressions :

您可以通过传递抑制文件来指示LeakSanitizer忽略某些泄漏.该文件每行必须包含一个禁止规则,每个规则的格式为 leak:< pattern> .该模式将与泄漏的符号堆栈轨迹进行子字符串匹配.如果函数名称,源文件名称或二进制文件名称匹配,则泄漏报告将被禁止.

You can instruct LeakSanitizer to ignore certain leaks by passing in a suppressions file. The file must contain one suppression rule per line, each rule being of the form leak:<pattern>. The pattern will be substring-matched against the symbolized stack trace of the leak. If either function name, source file name or binary file name matches, the leak report will be suppressed.

您可以通过设置环境变量 LSAN_OPTIONS = suppressions:my_suppressions.txt 在运行时传递文件.

You pass the file at runtime by setting the environment variable LSAN_OPTIONS=suppressions:my_suppressions.txt.

在您的特定情况下,由于< unknown module> 条目,可能很难找到合适的字符串来匹配.将 -fno-omit-frame-pointer 传递给编译器可能有助于获得更好的堆栈跟踪(无论如何在调试过程中都是有帮助的).

In your particular case, it may be difficult to find a good string to match against due to the <unknown module> entries. Passing -fno-omit-frame-pointer to the compiler might help to get better stack traces (which are helpful during debugging anyway).

这篇关于LeakSanitizer和泄漏的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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