可能的内存泄漏Valgrind的在OSX埃尔卡皮坦 [英] Possible Memory Leak Valgrind in OSX El Capitan

查看:364
本文介绍了可能的内存泄漏Valgrind的在OSX埃尔卡皮坦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了警告可能失去:2064字节1块OSX上使用优胜美地时,Valgrind的。是否有一个修复这个?我用BREW的valgrind安装

下面是如何再现的示例

 〜/ hello.c的猫
诠释主(){
    返回123;
}〜/的uname -a
达尔文mac.local 15.2.0 Darwin内核版本15.2.0:周五11月13日19时56分56秒的PST 2015年;根:XNU-3248.20.55〜2 / RELEASE_X86_64 x86_64的I386 MacBookAir6,2达尔文〜/铛--version
苹果LLVM 7.0.2版(铛-700.1.81)
目标:x86_64的 - 苹果darwin15.2.0
线程模型:POSIX〜/ Valgrind的--version
  的valgrind-3.11.0〜/ BREW的valgrind信息
Valgrind的:稳定的3.11.0(瓶装),HEAD
动态分析工具(内存,调试,分析)
http://www.valgrind.org/
/usr/local/Cellar/valgrind/3.11.0(328文件,46.7M)*
  从瓶中倒出
来源:https://github.com/Homebrew/homebrew/blob/master/Library/Formula/valgrind.rb〜/铿锵的hello.c -o hello.o〜/的valgrind --leak检查=全./hello.o
== == 7972 MEMCHECK,内存错误检测
== == 7972版权所有(C)2002 - 2015年和GNU GPL的,Julian Seward写等。
== == 7972 Valgrind的使用-3.11.0和LibVEX;与-h版权信息重新运行
== == 7972命令:./hello.o
== == 7972
== == 7972
== == 7972 HEAP摘要:
== == 7972使用在出口处:在187块22411字节
== == 7972总堆的使用情况:271 allocs,84的FreeS,28651字节分配
== == 7972
== == 7972在2064块1字节可能迷失在负的战绩62 57
== == 7972在0x10000817C:malloc_zone_malloc(以/usr/local/Cellar/valgrind/3.11.0/lib/valgrind/vg$p$pload_memcheck-amd64-darwin.so)
== == 7972通过0x1004F3EFD:_objc_copyClassNamesForImage(以/usr/lib/libobjc.A.dylib)
== == 7972通过0x1004E7182:协议()(在/usr/lib/libobjc.A.dylib)
== == 7972通过0x1004E7093:readClass(objc_class *,布尔,布尔)(以/usr/lib/libobjc.A.dylib)
== == 7972通过0x1004E4C13:gc_init(以/usr/lib/libobjc.A.dylib)
== == 7972通过0x1004EC24E:objc_initializeClassPair_internal(objc_class *,字符常量*,* objc_class,objc_class *)(在/usr/lib/libobjc.A.dylib)
== == 7972通过0x1004F9132:layout_string_create(以/usr/lib/libobjc.A.dylib)
== == 7972通过0x1004E783C:realizeClass(objc_class *)(在/usr/lib/libobjc.A.dylib)
== == 7972通过0x1004E7300:copySwiftV1MangledName(字符常量*,布尔)(以/usr/lib/libobjc.A.dylib)
== == 7972通过0x1004E72E9:copySwiftV1MangledName(字符常量*,布尔)(以/usr/lib/libobjc.A.dylib)
== == 7972通过0x1004E72E9:copySwiftV1MangledName(字符常量*,布尔)(以/usr/lib/libobjc.A.dylib)
== == 7972通过0x1004E72E9:copySwiftV1MangledName(字符常量*,布尔)(以/usr/lib/libobjc.A.dylib)
== == 7972
== == 7972泄漏摘要:
== == 7972肯定丢失:0字节0块
== == 7972失去了间接:0字节0块
== == 7972可能丢失:2064字节1块
== == 7972到达尚:0块0字节
== == 7972燮pressed:20347字节186块
== == 7972
== == 7972对于检测燮pressed错误计数,重新运行:-v
== == 7972错误摘要:从1上下文1错误(SUP pressed:17 17)


解决方案

Valgrind是主要用于Linux的工具,以及OSX较少的支持。这意味着,Valgrind的会产生大量的OSX误报。如果你想用晚餐preSS那些可能失去泄漏,然后添加 - 根燮pressions =所有(或 - -gen燮pressions = YES 如果你想挑选报道泄漏逐个)选择您的valgrind 电话。这将完成是打印出来文本块每个报告的内存泄漏,这将是这个样子:

  {
   < insert_a_sup pression_name_here>
   MEMCHECK:泄漏
   比赛泄漏种:间接
   好玩的:的malloc
   好玩的:__ Balloc_D2A
   好玩的:__ rv_alloc_D2A
   好玩的:__ DTOA
   好玩的:__ vfprintf
   好玩的:__ v2printf
   好玩:vfprintf_l
   好玩的:printf的
   好玩的:主
}

复制和粘贴,支架和所有,一个叫像 /Users/username/leak1.supp 文件。随意更改< ...> 为您的SUP pression的实际名称。然后当你调用的valgrind ,如果添加了一个 - 燮pressions = /用户/<用户名> /leak1.supp 选项,内存泄漏报告会燮pressed。为方便起见,你可以把东西在〜/ .valgrindrc 文件。这个文件可能看起来像

   - 工具= MEMCHECK
--leak检查=全
--show-可达= YES
--sup pressions = /用户/ benlindsay / leak1.supp
--sup pressions = /用户/ benlindsay / leak2.supp

或者,如果你可以测试你的code在Linux机器上,而不是,你会不会担心这一切;)

- 编辑 -

我得到了很多我的信息,从这个其他SO张贴

I'm getting a warning for possibly lost: 2,064 bytes in 1 blocks when using Valgrind on OSX Yosemite. Is there a fix to this? I installed valgrind using brew.

Below is an example of how to reproduce

~/cat hello.c
int main() {
    return 123;
}

~/uname -a
Darwin mac.local 15.2.0 Darwin Kernel Version 15.2.0: Fri Nov 13 19:56:56 PST 2015; root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64 i386 MacBookAir6,2 Darwin

~/clang --version
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.2.0
Thread model: posix

~/valgrind --version
  valgrind-3.11.0

~/brew info valgrind
valgrind: stable 3.11.0 (bottled), HEAD
Dynamic analysis tools (memory, debug, profiling)
http://www.valgrind.org/
/usr/local/Cellar/valgrind/3.11.0 (328 files, 46.7M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/valgrind.rb

~/clang hello.c -o hello.o

~/valgrind --leak-check=full ./hello.o
==7972== Memcheck, a memory error detector
==7972== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==7972== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==7972== Command: ./hello.o
==7972== 
==7972== 
==7972== HEAP SUMMARY:
==7972==     in use at exit: 22,411 bytes in 187 blocks
==7972==   total heap usage: 271 allocs, 84 frees, 28,651 bytes allocated
==7972== 
==7972== 2,064 bytes in 1 blocks are possibly lost in loss record 57 of 62
==7972==    at 0x10000817C: malloc_zone_malloc (in /usr/local/Cellar/valgrind/3.11.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==7972==    by 0x1004F3EFD: _objc_copyClassNamesForImage (in /usr/lib/libobjc.A.dylib)
==7972==    by 0x1004E7182: protocols() (in /usr/lib/libobjc.A.dylib)
==7972==    by 0x1004E7093: readClass(objc_class*, bool, bool) (in /usr/lib/libobjc.A.dylib)
==7972==    by 0x1004E4C13: gc_init (in /usr/lib/libobjc.A.dylib)
==7972==    by 0x1004EC24E: objc_initializeClassPair_internal(objc_class*, char const*, objc_class*, objc_class*) (in /usr/lib/libobjc.A.dylib)
==7972==    by 0x1004F9132: layout_string_create (in /usr/lib/libobjc.A.dylib)
==7972==    by 0x1004E783C: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==7972==    by 0x1004E7300: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==7972==    by 0x1004E72E9: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==7972==    by 0x1004E72E9: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==7972==    by 0x1004E72E9: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==7972== 
==7972== LEAK SUMMARY:
==7972==    definitely lost: 0 bytes in 0 blocks
==7972==    indirectly lost: 0 bytes in 0 blocks
==7972==      possibly lost: 2,064 bytes in 1 blocks
==7972==    still reachable: 0 bytes in 0 blocks
==7972==         suppressed: 20,347 bytes in 186 blocks
==7972== 
==7972== For counts of detected and suppressed errors, rerun with: -v
==7972== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 17 from 17)

解决方案

Valgrind is mostly a tool for Linux, and is less supported for OSX. This means that Valgrind will generate a lot of false positives on OSX. If you want to suppress those possibly lost leaks, then add the --gen-suppressions=all (or --gen-suppressions=yes if you want to pick and choose reported leaks one by one) option to your valgrind call. What this will do is print off a chunk of text for each reported memory leak that will look something like this:

{
   <insert_a_suppression_name_here>
   Memcheck:Leak
   match-leak-kinds: indirect
   fun:malloc
   fun:__Balloc_D2A
   fun:__rv_alloc_D2A
   fun:__dtoa
   fun:__vfprintf
   fun:__v2printf
   fun:vfprintf_l
   fun:printf
   fun:main
}

Copy and paste that, brackets and all, to a file called something like /Users/username/leak1.supp. Feel free to change the <...> to an actual name for your suppression. Then when you call valgrind, if you add a --suppressions=/Users/<username>/leak1.supp option, that memory leak report will be suppressed. To make this easier, you can just put stuff in a ~/.valgrindrc file. This file could look something like

--tool=memcheck
--leak-check=full
--show-reachable=yes
--suppressions=/Users/benlindsay/leak1.supp
--suppressions=/Users/benlindsay/leak2.supp

Or if you can just test your code on a Linux machine instead, you won't have to worry about all this ;)

--EDIT--

I got a lot of my info from this other SO post

这篇关于可能的内存泄漏Valgrind的在OSX埃尔卡皮坦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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