我在valgrind中遇到“额外”内存泄漏问题。例如,我创建了一个名为temp.cpp的测试程序:
int main() { return 0; }
在终端,我跑:
>> g++ -o temp.out temp.cpp
>> valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./temp.out
这会导致多次内存泄漏。怎么会这样?
==4438== LEAK SUMMARY:
==4438== definitely lost: 4,120 bytes in 2 blocks
==4438== indirectly lost: 2,288 bytes in 6 blocks
==4438== possibly lost: 8,336 bytes in 99 blocks
==4438== still reachable: 6,440 bytes in 13 blocks
==4438== suppressed: 5,020 bytes in 73 blocks
我尝试过运行其他.cpp文件,但我得到了完全相同的泄漏摘要。大约一个月前,当我尝试时,没有错。我可能已经升级了Xcode或其他东西,如果这可能是问题(?)。这些是我对g ++的设置:
配置为:
--prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Apple LLVM版本6.1.0(clang-602.0.53)(基于LLVM 3.6.0svn) 目标:x86_64-apple-darwin15.0.0 线程模型:posix
答案 0 :(得分:2)
似乎valgrind在MacOSX上存在问题。虽然这些问题没有得到解决,但可能的临时解决方案是使用抑制文件。有关详细信息,请查看this other answer
答案 1 :(得分:0)
我试图重现这个,但我无法在我的机器上。似乎最新的valgrind没有泄漏。尝试brew upgrade valgrind
C02QH2D7G8WM:simple userone$ valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./temp.out
==1917== Memcheck, a memory error detector
==1917== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==1917== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==1917== Command: ./temp.out
==1917==
==1917==
==1917== HEAP SUMMARY:
==1917== in use at exit: 22,177 bytes in 189 blocks
==1917== total heap usage: 255 allocs, 66 frees, 27,953 bytes allocated
==1917==
==1917== 2,064 bytes in 1 blocks are possibly lost in loss record 57 of 62
==1917== at 0x10000817C: malloc_zone_malloc (in /usr/local/Cellar/valgrind/3.11.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==1917== by 0x1005E0EFD: _objc_copyClassNamesForImage (in /usr/lib/libobjc.A.dylib)
==1917== by 0x1005D4182: protocols() (in /usr/lib/libobjc.A.dylib)
==1917== by 0x1005D4093: readClass(objc_class*, bool, bool) (in /usr/lib/libobjc.A.dylib)
==1917== by 0x1005D1C13: gc_init (in /usr/lib/libobjc.A.dylib)
==1917== by 0x1005D924E: objc_initializeClassPair_internal(objc_class*, char const*, objc_class*, objc_class*) (in /usr/lib/libobjc.A.dylib)
==1917== by 0x1005E6132: layout_string_create (in /usr/lib/libobjc.A.dylib)
==1917== by 0x1005D483C: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==1917== by 0x1005D4300: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==1917== by 0x1005D42E9: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==1917== by 0x1005D42E9: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==1917== by 0x1005D42E9: copySwiftV1MangledName(char const*, bool) (in /usr/lib/libobjc.A.dylib)
==1917==
==1917== LEAK SUMMARY:
==1917== definitely lost: 0 bytes in 0 blocks
==1917== indirectly lost: 0 bytes in 0 blocks
==1917== possibly lost: 2,064 bytes in 1 blocks
==1917== still reachable: 0 bytes in 0 blocks
==1917== suppressed: 20,113 bytes in 188 blocks
==1917==
==1917== For counts of detected and suppressed errors, rerun with: -v
==1917== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 17 from 17)