Valgrind总是会出错

时间:2018-06-14 09:04:03

标签: c++ g++ valgrind

我最近在我的macbook上安装了Valgrind以进行内存泄漏检测。但是,即使我写的代码应该完全正常,它总是会输出错误信息。

例如,我编写了以下虚拟cpp代码并将其存储在hello.cpp中:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
  return 0;
}

代码没有任何问题。然后我编译它并通过以下命令运行它:

$ g++ -o hello ./hello
$ ./hello

它也正常运行。没有产生错误或警告。但是,当我开始测试Valgrind时

$ valgrind --leak-check=yes  ./hello

然后在我的终端

中弹出下面的报告
==15065== Memcheck, a memory error detector
==15065== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==15065== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==15065== Command: ./hello
==15065== 
==15065== 
==15065== HEAP SUMMARY:
==15065==     in use at exit: 22,232 bytes in 190 blocks
==15065==   total heap usage: 256 allocs, 66 frees, 28,008 bytes allocated
==15065== 
==15065== 2,064 bytes in 1 blocks are possibly lost in loss record 59 of 62
==15065==    at 0x100008942: malloc_zone_malloc (in /usr/local/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==15065==    by 0x1005E2EFD: _objc_copyClassNamesForImage (in /usr/lib/libobjc.A.dylib)
==15065==    by 0x1005D6182: protocols() (in /usr/lib/libobjc.A.dylib)
==15065==    by 0x1005D6093: readClass(objc_class*, bool, bool) (in /usr/lib/libobjc.A.dylib)
==15065==    by 0x1005D3C13: gc_init (in /usr/lib/libobjc.A.dylib)
==15065==    by 0x1005DB24E: objc_initializeClassPair_internal(objc_class*, char const*, objc_class*, objc_class*) (in /usr/lib/libobjc.A.dylib)
==15065==    by 0x1005E8132: layout_string_create (in /usr/lib/libobjc.A.dylib)
==15065==    by 0x1005D683C: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==15065==    by 0x1005D6300: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==15065==    by 0x1005D62E9: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==15065==    by 0x1005D62E9: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==15065==    by 0x1005D62E9: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==15065== 
==15065== LEAK SUMMARY:
==15065==    definitely lost: 0 bytes in 0 blocks
==15065==    indirectly lost: 0 bytes in 0 blocks
==15065==      possibly lost: 2,064 bytes in 1 blocks
==15065==    still reachable: 0 bytes in 0 blocks
==15065==         suppressed: 20,168 bytes in 189 blocks
==15065== 
==15065== For counts of detected and suppressed errors, rerun with: -v
==15065== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 15 from 15)

嗯...最后一行&#34;来自1个背景的错误&#34;对我来说没有任何意义。我想知道它是否提到了'#34;可能丢失&#34;参见LEAK SUMMARY。但是如何在虚拟程序中出现任何泄漏?

0 个答案:

没有答案