最重要的错误信息类似如下,描述问题1,堆栈溢出:
==19182== Invalid write of size 4==19182== at 0x804838F: f (example.c:6)==19182== by 0x80483AB: main (example.c:11)==19182== Address 0x1BA45050 is 0 bytes after a b==19182== at 0x1B8FF5CD: malloc (vg_replace_ma==19182== by 0x8048385: f (example.c:5)==19182== by 0x80483AB: main (example.c:11)说明:
内存泄露信息类似如下:
==19182== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1==19182== at 0x1B8FF5CD: malloc (vg_replace_malloc.c:130)==19182== by 0x8048385: f (a.c:5)==19182== by 0x80483AB: main (a.c:11)栈追踪信息告诉你内存泄露在哪被产生;很遗憾,memcheck不能告诉你为什么导致内存泄露。
memcheck也会报告没有初始化的变量,最常见信息是"Conditional jump or move depends on uninitialised value(s)".可能很困难去判断错误的原因,尝试使用--track-origins=yes可以获得额外信息,这会使memcheck运行较慢,但是额外信息会帮助你节省很多时间去那些未初始化的值。