【问题标题】:What do the suppressed leaks mean in Valgrind?Valgrind 中被抑制的泄漏意味着什么?
【发布时间】:2011-12-28 14:49:15
【问题描述】:

我在文件fifo.hfifo.c 中开发了FIFO 列表(队列)的纯C 实现,并编写了一个测试程序testfifo.c,我将其编译为./bin/testfifo。节点结构在list.h中定义。

我像这样在 OS X 10.6 上通过 Valgrind 运行我的程序

valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./bin/testfifo

并得到以下输出

==54688== Memcheck, a memory error detector
==54688== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==54688== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==54688== Command: bin/testfifo
==54688== 
--54688-- bin/testfifo:
--54688-- dSYM directory is missing; consider using --dsymutil=yes
==54688== 
==54688== HEAP SUMMARY:
==54688==     in use at exit: 88 bytes in 1 blocks
==54688==   total heap usage: 11 allocs, 10 frees, 248 bytes allocated
==54688== 
==54688== LEAK SUMMARY:
==54688==    definitely lost: 0 bytes in 0 blocks
==54688==    indirectly lost: 0 bytes in 0 blocks
==54688==      possibly lost: 0 bytes in 0 blocks
==54688==    still reachable: 0 bytes in 0 blocks
==54688==         suppressed: 88 bytes in 1 blocks
==54688== 
==54688== For counts of detected and suppressed errors, rerun with: -v
==54688== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

根据泄漏摘要,没有泄漏,但我仍然想知道“抑制”泄漏是什么。另外,alloc 和 free 的数量不匹配,所以我不确定是否有泄漏。

----编辑----

跑步

valgrind --tool=memcheck --leak-check=full --show-reachable=yes -v ./bin/testfifo

在 OS X 10.6 上会产生相当长且令人困惑的输出,但我已经运行了

valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./bin/testfifo

在 Linux 机器上得到以下输出:

==32688== Memcheck, a memory error detector
==32688== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==32688== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==32688== Command: bin/testfifo
==32688== 
==32688== 
==32688== HEAP SUMMARY:
==32688==     in use at exit: 0 bytes in 0 blocks
==32688==   total heap usage: 10 allocs, 10 frees, 160 bytes allocated
==32688== 
==32688== All heap blocks were freed -- no leaks are possible
==32688== 
==32688== For counts of detected and suppressed errors, rerun with: -v
==32688== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

alloc's 和 free's 现在匹配,因此 OS X 上的额外分配似乎是由于某些系统库造成的,正如已建议的那样。

我已经使用-v 选项运行了相同的命令,以显示 4 个被抑制的错误,但我没有得到任何易于理解的新信息。

【问题讨论】:

    标签: c valgrind


    【解决方案1】:

    这些是代码之外的泄漏、(可能是共享的)库中的泄漏或已知的误报。使用-v 运行 valgrind 应该会告知您使用的抑制。

    【讨论】:

    • 错误检查工具会检测系统库中的许多问题,例如预装在您的操作系统中的 C 库。你不能轻易地修复这些,但你不想看到这些错误(是的,有很多!)所以 Valgrind 读取错误列表以在启动时抑制。构建系统时,./configure 脚本会创建一个默认的抑制文件。
    • 其中一些也不是库的问题,而是已知的库在可能在您的应用程序外部的进程之间共享内存。
    • @MichaelMior 是的,我看到 memcheck 出现误报。
    • 谢谢,所有这些信息真的很有帮助!我在 Linux 系统上尝试过,现在可以确定我的程序不会泄漏内存。
    猜你喜欢
    • 1970-01-01
    • 2010-12-01
    • 1970-01-01
    • 2014-12-07
    • 2013-03-09
    • 1970-01-01
    • 2012-02-28
    • 1970-01-01
    相关资源
    最近更新 更多