Valgrind 报告 OS X 10.8.1 上的内存泄漏 [英] Valgrind reports leaked memory on OS X 10.8.1

查看:19
本文介绍了Valgrind 报告 OS X 10.8.1 上的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 OS X 10.8.1, Mountain Lion 上使用 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,只有有限的支持".尽管如此,这个错误报告说(斜体我的):

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:

我能够轻松地在 10.8.1 上编译 Valgrind,但是当我在几个小的 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 的调用确实适当地增加了堆分配计数.
  • 使用 -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 the dSYM 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.

如果您仍想运行它,请打印有关虚假泄漏的详细信息 (--leak-check=full) 并将其用于 禁止关于他们的消息.

If you still want to run it, print detailed information about spurious leaks (--leak-check=full) and use it to suppress messages about them.

这篇关于Valgrind 报告 OS X 10.8.1 上的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆