c - Valgrind:是否有内存泄漏?

标签 c linux memory-leaks valgrind

我在我的程序上运行 valgrind 并得到以下输出(我将忽略上面的 83 个错误,如果我应该将它们包含在日志中请告诉我):

==9723== LEAK SUMMARY:
==9723==    definitely lost: 0 bytes in 0 blocks
==9723==    indirectly lost: 0 bytes in 0 blocks
==9723==      possibly lost: 4,676 bytes in 83 blocks
==9723==    still reachable: 88,524 bytes in 579 blocks
==9723==         suppressed: 0 bytes in 0 blocks
==9723== Reachable blocks (those to which a pointer was found) are not shown.
==9723== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==9723== 
==9723== For counts of detected and suppressed errors, rerun with: -v
==9723== ERROR SUMMARY: 83 errors from 83 contexts (suppressed: 3 from 3)

无论我运行程序多长时间,无论是 2 秒还是 2 分钟,这都是我从 valgrind 获得的输出。

由于“可能丢失”不会随着时间的推移而增加,是否可以安全地假设我没有内存泄漏?

这些错误似乎都来自 libglib,并围绕着 g_malloc0 和 g_realloc。

最佳答案

valgrind 中的

Possibly lost 错误涵盖了涉及指针链的场景子集。我肯定会追查造成这种情况的原因,直到您确认这不是问题(至少,您的内存占用量不应增加),因为它可能表明您的代码中存在其他逻辑问题。

This帖子有一个更详细地解决它的答案。

有关更多信息,您还可以查看 relevant section在 valgrind 手册中。

关于c - Valgrind:是否有内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20848754/

相关文章:

c - 从优化为循环不变的循环中的结构指针取消引用成员吗?

c - 为什么在写入使用字符串文字初始化的 "char *s"而不是 "char s[]"时出现段错误?

c - C 中日历作业的问题

c - Windows 控制台中奇怪的显示 EOF 字符

c - Linux 系统调用中 fcntl 中 F_DUPFD 的用法是什么

linux - shell 脚本 1 : [: [: unexpected operator

linux - 有没有一种方法可以确定 Linux 中的音频 channel 布局?

c++ - QSerialBus 工作中的内存泄漏

c - 父进程调用fork()后子进程内存泄漏,为什么?

c# - 未调用行为的 OnDetaching 函数