valgrind - 如何让 Valgrind 显示行错误?

标签 valgrind

如何让 Valgrind 准确显示错误发生的位置?我编译了我的程序(通过 PuTTy 在 Windows 机器上通过 Linux 终端)添加了 -g 调试选项。

当我运行 Valgrind 时,我得到了泄漏和堆摘要,并且我肯定丢失了内存,但我从未获得有关它发生的位置的信息(文件名、行)。 Valgrind 不应该在我分配内存后在哪一行告诉我,稍后它无法释放内存吗?

==15746==
==15746== HEAP SUMMARY:
==15746==     in use at exit: 54 bytes in 6 blocks
==15746==   total heap usage: 295 allocs, 289 frees, 11,029 bytes allocated
==15746==
==15746== LEAK SUMMARY:
==15746==    definitely lost: 12 bytes in 3 blocks
==15746==    indirectly lost: 42 bytes in 3 blocks
==15746==      possibly lost: 0 bytes in 0 blocks
==15746==    still reachable: 0 bytes in 0 blocks
==15746==         suppressed: 0 bytes in 0 blocks
==15746== Rerun with --leak-check=full to see details of leaked memory
==15746==
==15746== For counts of detected and suppressed errors, rerun with: -v
==15746== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 15 from 8)

最佳答案

我已经多次被这个问题困扰,并且无法弄清楚为什么'--leak-check=full'对我不起作用,所以我想我应该提出tune2fs评论。

最可能的问题是您(不是 ShrimpCrackers,而是现在正在阅读这篇文章的任何人)将 --leak-check=full 放在命令行末尾。 Valgrind 希望您在输入实际命令行来运行程序之前发布该标志。

即:

valgrind --leak-check=full ./myprogram

不是:

valgrind ./myprogram --leak-check=full

关于valgrind - 如何让 Valgrind 显示行错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7797864/

相关文章:

c - Mac OS X 上的 Valgrind 错误 printf a double

c - 为什么用 gcc-5.2.0 编译程序时 valgrind 没有发现泄漏

CS50 PSET4 无法释放拼写器中的内存

c - Valgrind 警告 : Should I Take It Seriously

c - 尝试重新排序链表时 free() 无效

c++ - C++开发中使用Valgrind?

Windows Callgrind 结果浏览器,替代 KCacheGrind

c++ - Callgrind 内联函数

c++ - Valgrind 不会返回源代码行!

c - 在 C 代码中获取 valgrind 错误