令人困惑的Valgrind输出显示间接丢失的内存泄漏但没有明确丢失或可能丢失

时间:2014-03-26 18:36:10

标签: c++ macos valgrind

我在macos x 10.8上运行valgrind。 Valgrind在创业时说道。

"==11312== WARNING: Support on MacOS 10.8 is experimental and mostly broken.
==11312== WARNING: Expect incorrect results, assertions and crashes.
==11312== WARNING: In particular, Memcheck on 32-bit programs will fail to
==11312== WARNING: detect any errors associated with heap-allocated data."

Valgrind正在提供此漏洞摘要:

"LEAK SUMMARY:
==11312==    definitely lost: 0 bytes in 0 blocks
==11312==    indirectly lost: 48 bytes in 2 blocks
==11312==      possibly lost: 0 bytes in 0 blocks
==11312==    still reachable: 45,857 bytes in 270 blocks
==11312==         suppressed: 16,805 bytes in 87 blocks"

根据valgrinds faq,http://valgrind.org/docs/manual/faq.html#faq.deflost,“间接丢失”意味着您的程序在基于指针的结构中泄漏内存。 (例如,如果二叉树的根节点“绝对丢失”,则所有子节点将“间接丢失”。)如果您修复了“绝对丢失”的泄漏,“间接丢失”的泄漏应该消失。

我没有任何明显丢失的泄漏,甚至可能丢失泄漏修复。我应该修复什么?由于10.8中valgrind的实验性质,这个报告可能是一个错误吗?

我相信我将其编译为64位程序,因为编译器是64位编译器。

2 个答案:

答案 0 :(得分:1)

我回答自己的问题感到很奇怪。

是的,valgrind在mac上的报告不正确。根据linux上的valgrind,所有堆块都被释放,因此不会发生泄漏。

我真的希望valgrind能解决mac的问题,因为我现在主要在mac上开发。

答案 1 :(得分:0)

Valgrind已经updated。使用(如果你使用自制软件):

brew unlink valgrind
brew install valgrind

而且,瞧瞧:

==23998== LEAK SUMMARY:
==23998==    definitely lost: 0 bytes in 0 blocks
==23998==    indirectly lost: 0 bytes in 0 blocks
==23998==      possibly lost: 0 bytes in 0 blocks
==23998==    still reachable: 76,800 bytes in 2 blocks
==23998==         suppressed: 58,420 bytes in 359 blocks