【发布时间】:2011-12-28 14:49:15
【问题描述】:
我在文件fifo.h 和fifo.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 个被抑制的错误,但我没有得到任何易于理解的新信息。
【问题讨论】: