我对 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 上有问题。虽然这些问题尚未解决,但可能的临时解决方案是使用抑制文件。更多详情请查看this other answer
关于c++ - 空文件中的 Valgrind C++ 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33657871/