【发布时间】:2019-03-12 14:11:05
【问题描述】:
我们使用valgrind 作为我们 CI 流程的一部分。如果有一些内存问题,valgrind 必须返回非零代码,并报告此事件。这就是我们运行它的方式:
valgrind --error-exitcode=1 --tool=memcheck --leak-check=full \
--errors-for-leak-kinds=definite --show-leak-kinds=definite \
--track-origins=yes ./some_cgo_application
(...)
==25182== HEAP SUMMARY:
==25182== in use at exit: 2,416,970 bytes in 34,296 blocks
==25182== total heap usage: 83,979 allocs, 49,684 frees, 5,168,335 bytes allocated
==25182==
==25182== LEAK SUMMARY:
==25182== definitely lost: 0 bytes in 0 blocks
==25182== indirectly lost: 0 bytes in 0 blocks
==25182== possibly lost: 3,024 bytes in 7 blocks
==25182== still reachable: 2,413,946 bytes in 34,289 blocks
==25182== of which reachable via heuristic:
==25182== newarray : 520 bytes in 1 blocks
==25182== suppressed: 0 bytes in 0 blocks
==25182== Reachable blocks (those to which a pointer was found) are not shown.
==25182== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==25182==
==25182== For counts of detected and suppressed errors, rerun with: -v
==25182== ERROR SUMMARY: 20 errors from 5 contexts (suppressed: 0 from 0)
目前我们只对definitly lost 的内存感兴趣。如果确定没有块丢失,valgrind 的退出代码预计为零。但是,尽管有 --errors-for-leak-kinds=definite --show-leak-kinds=definite 选项,它仍返回 1。
echo $?
1
是否还有其他选项可以帮助实现预期结果?
【问题讨论】:
标签: memory-leaks valgrind exit-code