Valgrind中的抑制泄漏是什么意思?

20

我已经开发了一个C语言实现的FIFO列表(队列),代码在fifo.hfifo.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)

根据泄漏摘要,没有发生泄漏,但我仍然想知道“被抑制的”泄漏是什么意思。此外,分配和释放的数量不匹配,因此我不确定是否存在泄漏。

----编辑----

运行

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和free匹配了,所以在OS X上的额外分配似乎是由于某个系统库导致的,正如之前所建议的那样。

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

1个回答

24

这些泄漏不是你的代码中出现的,而是在(可能是共享的)库或已知的误报中。使用-v选项运行valgrind应该能通知你使用的抑制信息。


9
错误检测工具可以检测系统库(例如预装在您的操作系统中的C库)中的多个问题。这些问题通常难以修复,但您可能不想看到这些错误(是的,有很多错误!)。为此,Valgrind在启动时读取一个错误抑制列表。在构建系统时,./configure脚本会创建一个默认的错误抑制文件。 - Sjoerd
2
其中一些问题也不是库的问题,而是针对已知会在进程之间共享内存(可能是应用程序外部的进程)的库。 - Michael Mior
@MichaelMior 是的,我也见过memcheck的误报。 - cnicutar
谢谢,所有的信息都非常有帮助!我在 Linux 系统上尝试了一下,现在可以确定我的程序不会泄漏内存了。 - Genba

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接