debugging Valgrind输出中的错误摘要?

cgfeq70w  于 2023-03-30  发布在  其他
关注(0)|答案(2)|浏览(150)

我看过一些关于valgrind的帖子,但没有一个帖子帮助我理解valgrind输出的解释。我用valgrind运行了两个程序(都有内存泄漏)
测试1的样本输出

==20422== LEAK SUMMARY:
==20422== definitely lost: 448 bytes in 3 blocks
==20422== indirectly lost: 786,460 bytes in 1 blocks
==20422== possibly lost: 1,576,052 bytes in 46 blocks
==20422== still reachable: 1,077,107 bytes in 2,333 blocks
==20422== suppressed: 0 bytes in 0 blocks
==20422== Rerun with --leak-check=full to see details of leaked memory
==20422==
==20422== For counts of detected and suppressed errors, rerun with: -v
==20422== ERROR SUMMARY: 98307 errors from 5 contexts (suppressed: 2 from 2)
Killed

测试2的输出

==20875== HEAP SUMMARY:
==20875== in use at exit: 1,059,198 bytes in 2,047 blocks
==20875== total heap usage: 3,019 allocs, 972 frees, 4,496,090 bytes allocated
==20875==
==20875== LEAK SUMMARY:
==20875== definitely lost: 328 bytes in 2 blocks
==20875== indirectly lost: 0 bytes in 0 blocks
==20875== possibly lost: 1,600 bytes in 5 blocks
==20875== still reachable: 1,057,270 bytes in 2,040 blocks
==20875== suppressed: 0 bytes in 0 blocks
==20875== Rerun with --leak-check=full to see details of leaked memory
==20875==
==20875== For counts of detected and suppressed errors, rerun with: -v
==20875== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)

如果您查看错误摘要,一个输出显示有错误,另一个输出显示没有错误(最终两者都有泄漏)
我的问题是- -在valgrind中什么算错误?(valgrind手册没有帮助我)

gz5pxeao

gz5pxeao1#

内存泄漏不被认为是错误,它们不会影响程序的逻辑。
错误是诸如无效的读取和写入之类的事情。
根据备注进行更新:测试1中的无效读取和写入针对5个不同的存储器区域,其被访问98307次。
查看泄漏,测试1中的大量间接损失可能表明链接的数据结构,其中仅删除了根。
test 2中的漏洞并不太严重,正如valgrind建议的那样,使用--leak-check=full重新运行,这应该能指出是哪一段代码导致了问题。
有关错误的完整解释,请参见here

whhtz7ly

whhtz7ly2#

我没有足够的声誉来评论接受的答案,只是在这里附加一些有用的信息,因为我也在搜索valgrind报告中的真正错误。
首先,错误遵循“ERROR SUMMARY”肯定是必须修复的错误。有些泄漏也被视为错误,这取决于使用的cmd选项。
“如果指定了--leak-check=full。则选项--errors-for-leak-kinds=控制要视为错误的泄漏类型集。默认值为--errors-for-leak-kinds=definite,possible”
我在这里找到:https://valgrind.org/docs/manual/mc-manual.html#mc-manual.errormsgs

相关问题