gpt4 book ai didi

c++ - 无论如何检测到 valgrind 泄漏

转载 作者:太空狗 更新时间:2023-10-29 22:57:16 26 4
gpt4 key购买 nike

即使我编译并运行这样的程序:

int main() {
return 0;
}

当我运行 valgrind --leak-check=yes ./a.out

时出现以下 valgrind 错误
==26391== LEAK SUMMARY:
==26391== definitely lost: 0 bytes in 0 blocks
==26391== indirectly lost: 0 bytes in 0 blocks
==26391== possibly lost: 72 bytes in 3 blocks
==26391== still reachable: 200 bytes in 6 blocks
==26391== suppressed: 18,528 bytes in 153 blocks
==26391== Reachable blocks (those to which a pointer was found) are not shown.
==26391== To see them, rerun with: --leak-check=full --show-leak-kinds=all

我正在使用 clang++ test.cpp 进行编译。我完全不知道如何解决这个问题。

谢谢!

最佳答案

Valgrind 手册有以下关于可能丢失的内容

This means that a chain of one or more pointers to the block has been found, but at least one of the pointers is an interior-pointer. This could just be a random value in memory that happens to point into a block, and so you shouldn’t consider this ok unless you know you have interior-pointers.

这意味着所有报告的 possibly lost 事件都不是泄漏。这需要通过代码细读来确认以检查泄漏。

对于您的特定情况,我们知道您的代码中没有发生泄漏。您可能想使用 --leak-check=full --show-leak-kinds=all

重新运行 valgrind

关于c++ - 无论如何检测到 valgrind 泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45125754/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com