【问题标题】:valgrind mac os mem leakvalgrind macos 内存泄漏
【发布时间】:2011-03-07 23:40:57
【问题描述】:

今天我在我的 Mac os x 10.6 上安装了 valgrind 并尝试对其进行测试。结果是系统中出现了奇怪的内存泄漏。我所做的只是创建简单的 c 文件来获取一些堆内存并立即释放它。当我运行 valgrind 时,它显示了这样的内容

Realfrees-MacBook-Pro:C Realfree$ valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./a.out 
==2621== Memcheck, a memory error detector
==2621== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==2621== Using Valgrind-3.6.0 and LibVEX; rerun with -h for copyright info
==2621== Command: ./a.out
==2621== 
--2621-- ./a.out:
--2621-- dSYM directory is missing; consider using --dsymutil=yes
==2621== 
==2621== HEAP SUMMARY:
==2621==     in use at exit: 88 bytes in 1 blocks
==2621==   total heap usage: 2 allocs, 1 frees, 92 bytes allocated
==2621== 
==2621== 88 bytes in 1 blocks are still reachable in loss record 1 of 1
==2621==    at 0x100010915: malloc (vg_replace_malloc.c:236)
==2621==    by 0x1000260EB: get_or_create_key_element (in /usr/lib/libSystem.B.dylib)
==2621==    by 0x100026008: _keymgr_get_and_lock_processwide_ptr_2 (in /usr/lib/libSystem.B.dylib)
==2621==    by 0x100025FCF: __keymgr_initializer (in /usr/lib/libSystem.B.dylib)
==2621==    by 0x1000245E7: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==2621==    by 0x7FFF5FC0D4FF:  ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==2621==    by 0x7FFF5FC0BCEB: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int) (in /usr/lib/dyld)
==2621==    by 0x7FFF5FC0BC9C: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int) (in /usr/lib/dyld)
==2621==    by 0x7FFF5FC0BDA5: ImageLoader::runInitializers(ImageLoader::LinkContext const&) (in /usr/lib/dyld) 
==2621==    by 0x7FFF5FC020EE: dyld::initializeMainExecutable() (in /usr/lib/dyld)
==2621==    by 0x7FFF5FC06980: dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**) (in /usr/lib/dyld)
==2621==    by 0x7FFF5FC016D1: dyldbootstrap::start(macho_header const*, int, char const**, long) (in /usr/lib/dyld)
==2621== 
==2621== LEAK SUMMARY:
==2621==    definitely lost: 0 bytes in 0 blocks
==2621==    indirectly lost: 0 bytes in 0 blocks
==2621==      possibly lost: 0 bytes in 0 blocks
==2621==    still reachable: 88 bytes in 1 blocks
==2621==         suppressed: 0 bytes in 0 blocks
==2621== 
==2621== For counts of detected and suppressed errors, rerun with: -v
==2621== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

仍然可以访问一定数量的内存。知道如何解决吗?或者这对于mac来说是正常的

附:我用命令 ls -l 运行了 valgrind,它显示了一堆仍然可以访问的块。 我不确定这是 mac 上的正常行为。 下面是命令行“valgrind --tool=memcheck ls -l”的结果:

==2734== 
==2734== HEAP SUMMARY:
==2734==     in use at exit: 118,331 bytes in 52 blocks
==2734==   total heap usage: 1,253 allocs, 1,201 frees, 214,242 bytes allocated
==2734== 
==2734== LEAK SUMMARY:
==2734==    definitely lost: 0 bytes in 0 blocks
==2734==    indirectly lost: 0 bytes in 0 blocks
==2734==      possibly lost: 0 bytes in 0 blocks
==2734==    still reachable: 118,331 bytes in 52 blocks
==2734==         suppressed: 0 bytes in 0 blocks
==2734== Rerun with --leak-check=full to see details of leaked memory
==2734== 
==2734== For counts of detected and suppressed errors, rerun with: -v
==2734== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

【问题讨论】:

    标签: c macos valgrind


    【解决方案1】:

    您可能需要使用valgrind suppressions file for Mac。看起来一些进程范围的内存是在进程退出时分配的,而不是释放的。试试valgrind --suppressions=<path to suppression file>

    【讨论】:

      【解决方案2】:

      对于 Mac OS X Lion,您应该使用这个抑制文件:https://github.com/svn2github/valgrind/blob/master/darwin11.supp

      【讨论】:

      • 有 10.9 的吗?
      • @Dr.JohnnyMohawk 最新的资源都应该列出here,包括用于 OS X 10.9 / Darwin 13.0 的资源(参见here 了解 Darwin 和 OS X 版本之间的对应关系,或在终端输入uname -sr)。
      猜你喜欢
      • 2013-06-24
      • 2020-03-31
      • 2016-03-15
      • 2014-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      相关资源
      最近更新 更多