【问题标题】:Valgrind: Memory leak or no?Valgrind:内存泄漏与否?
【发布时间】:2014-01-17 21:10:53
【问题描述】:

我正在我的程序上运行 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)

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

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

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

【问题讨论】:

标签: c linux memory-leaks valgrind


【解决方案1】:

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

This 的帖子有一个更详细的答案。

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

【讨论】:

    猜你喜欢
    • 2015-06-28
    • 2013-06-24
    • 2020-03-31
    • 2016-03-15
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多