Valgrind C++内存在空文件中泄漏
Valgrind C++ memory leak in empty file
我在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
看来valgrind在MacOSX上有问题。虽然这些问题尚未解决,但一个可能的临时解决方案是使用抑制文件。有关更多详细信息,请查看其他答案
我试图复制这个,但在我的机器上无法复制。最新的valgrind似乎没有泄漏。尝试酿造升级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)
相关文章:
- .cpp和.h文件中的模板专用化声明
- valgrind-hellgrind与泄漏检查的结果不同
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 是标头文件中使用“新”定义的成员指针泄漏
- 不可预测的文件描述符泄漏
- 从文件读取时内存泄漏
- 使用缓冲区写入文件时,C 内存会泄漏
- 我的C++文件中是否有可能的内存泄漏
- C++读取文件时可能发生内存泄漏
- 从C++打开文件对话框时,JNI内存泄漏
- 当在头文件上而不是在CPP文件上实现时,析构函数会导致内存泄漏——仅在linux上实现
- Valgrind的Qt内存泄漏抑制文件
- 使用Windbg从转储文件中分析可能的内存泄漏
- Valgrind内存泄漏错误的文件跟踪
- 打开文件对话框和内存泄漏
- 使用FindFile和文件句柄的c++内存泄漏
- 有没有办法找到泄漏的内存使用核心文件
- Solaris中如何检测文件泄漏以及相应的代码
- clang++生成的可执行文件会泄漏内存,关于std::function和lambda
- 内存泄漏检测文件错误