用 valgrind 检测内存问题
在 Memcheck 下运行程序,找出泄漏与非法访问。
运行 valgrind --leak-check=full ./程序,获得泄漏与错误报告。
01命令
命令
$ valgrind --leak-check=full ./my-program02作用说明
Valgrind 模拟 CPU 并跟踪每次内存操作,因此 use-after-free、未初始化读取和泄漏都会带调用栈报告。它对原生调试无可替代,且只在命令行工作流中才有意义。
03风险
!注意: 模拟会使执行慢一个数量级,且需要调试符号才能给出有用的行号。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- valgrind.1.en.html manual page (Debian bookworm)依据: Documents valgrind and the memcheck tool.
最后验证: 2026-10-13 · 分类: 开发者