Valgrind的报告在OS X 10.8.1泄漏内存
我使用的是OS X 10.8.1,山狮Valgrind的版本3.8.0。关于与10.8.1的兼容性, Valgrind的的网站说(斜体矿):
I'm using Valgrind version 3.8.0 on OS X 10.8.1, Mountain Lion. Regarding compatibility with 10.8.1, Valgrind's site says (italics mine):
的 Valgrind的3.8.0作品上的{X86,AMD64} -darwin键(Mac OS X 10.6和10.7,与10.8的支持有限)。
Valgrind 3.8.0 works on {x86,amd64}-darwin (Mac OS X 10.6 and 10.7, with limited support for 10.8).
我知道的话,就只有有限支持10.8.1。尽管如此,这个bug报告说(斜体矿):
I know, then, that there is only "limited support" for 10.8.1. Nonetheless, this bug report says (italics mine):
此的(最新的3.8.0版本)的使的 Valgrind的的
编译并能够在OSX 10.8上运行的小程序。然而,被警告
它仍然具有较大的应用断言和32位程序不
在所有适当的检查(大部分错误是由MEMCHECK遗漏)。
This (the latest 3.8.0 release) makes Valgrind compile and able to run small programs on OSX 10.8. Be warned however that it still asserts with bigger apps, and 32 bit programs are not checked properly at all (most errors are missed by Memcheck).
好吧,这很好。所以Valgrind把工作,如果气质,在10.8.1。所以现在我的问题:
Ok, that's fine. So Valgrind should work, if temperamentally, on 10.8.1. So now my question:
我能得到Valgrind的在10.8.1编译有点麻烦,但我看到了一些奇怪的结果,当我跑了它的一对夫妇的小C程序。为了尽量减少问题的可能原因,我最终写了下面的程序:
I was able to get Valgrind to compile on 10.8.1 with little trouble, but I saw some weird results when I ran it on a couple small C programs. To try and reduce the possible causes of the issue, I eventually wrote the following "program":
int main () {
return 0;
}
不是很精彩,小房间的错误,我会说。然后,我通过Valgrind的编译和运行它:
Not very exciting, and little room for bugs, I'd say. Then, I compiled and ran it through Valgrind:
gcc testC.c
valgrind ./a.out
下面是我的输出:
==45417== Command: ./a.out
==45417==
==45417== WARNING: Support on MacOS 10.8 is experimental and mostly broken.
==45417== WARNING: Expect incorrect results, assertions and crashes.
==45417== WARNING: In particular, Memcheck on 32-bit programs will fail to
==45417== WARNING: detect any errors associated with heap-allocated data.
==45417==
--45417-- ./a.out:
--45417-- dSYM directory is missing; consider using --dsymutil=yes
==45417==
==45417== HEAP SUMMARY:
==45417== in use at exit: 58,576 bytes in 363 blocks
==45417== total heap usage: 514 allocs, 151 frees, 62,442 bytes allocated
==45417==
==45417== LEAK SUMMARY:
==45417== definitely lost: 8,624 bytes in 14 blocks
==45417== indirectly lost: 1,168 bytes in 5 blocks
==45417== possibly lost: 4,925 bytes in 68 blocks
==45417== still reachable: 43,859 bytes in 276 blocks
==45417== suppressed: 0 bytes in 0 blocks
==45417== Rerun with --leak-check=full to see details of leaked memory
==45417==
==45417== For counts of detected and suppressed errors, rerun with: -v
==45417== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
我知道Valgrind是没有准备好黄金时间10.8.1。尽管如此,我很想能够在这里使用它 - 我只需要使用它的小程序,并没有什么是关键任务一下,结果被当场上。但显然,它的报告中,这似乎不太可能是泄漏的程序一吨泄漏。因此:
I know that Valgrind is not ready for prime-time on 10.8.1. Nonetheless, I would love to be able to use it here – I only need to use it on small programs, and nothing is mission-critical about the results being spot-on. But clearly, it is reporting a ton of leaks in a program that seems very unlikely to be leaking. Thus:
我应该怎么做才能解决这个问题?
其他信息:
- 添加故意泄露整数的确实的递增肯定丢失通过适当的4个字节数。
- 同样,通过不释放内存泄漏故意要调用malloc的确实的递增堆ALLOC适当计数。
- 与
-g
标志进行编译,然后再运行Valgrind的(解决的dSYM目录丢失
错误)并导致该错误消失,但是的不的改变吨被报告的内存泄漏的问题。
- Adding an intentionally leaked integer does increment the "definitely lost" count by the appropriate 4 bytes.
- Similarly, intentionally leaking a call to malloc by not freeing the memory does increment the heap alloc count appropriately.
- Compiling with the
-g
flag and then running to Valgrind (to address thedSYM directory is missing
error) does cause that error to disappear, but does not change the issue of tons of memory leaks being reported.
它会告诉你正确的有:
预计不正确的结果,断言和崩溃。
Expect incorrect results, assertions and crashes.
如果您仍然想运行它,打印有关虚假泄漏的详细信息( - 泄漏检查=全
),并用它来的sup$p$pss 消息关于他们。
If you still want to run it, print detailed information about spurious leaks (--leak-check=full
) and use it to suppress messages about them.