簡體   English   中英

valgrind mac os 內存泄漏

[英]valgrind mac os mem leak

今天我在我的 Mac os x 10.6 上安裝了 valgrind 並嘗試測試它。 結果是系統中出現了奇怪的 memory 泄漏。 我所做的只是創建簡單的 c 文件,獲取一些堆 memory 並立即釋放它。 當我運行 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)

其中一定數量的 memory 仍然可以訪問。 知道如何解決嗎? 或者這對 mac 來說是正常的

PS 我用命令 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)

您可能需要為Mac使用valgrind抑制文件 看起來某些進程范圍的內存是在進程退出時未釋放的。 嘗試使用valgrind --suppressions=<path to suppression file>

對於Mac OS X Lion,您應該使用此抑制文件: https//github.com/svn2github/valgrind/blob/master/darwin11.supp

其他 OSX 版本的抑制文件可以在這里找到: https://github.com/LouisBrunner/valgrind-macos

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM