我正在使用命令:
valgrind --tool=memcheck --leak-check=yes ./prog
当使用测试脚本运行时,我没有内联错误消息或警告,我只是获得堆摘要和泄漏摘要。
我错过了一面旗帜吗?
==31420== HEAP SUMMARY:
==31420== in use at exit: 1,580 bytes in 10 blocks
==31420== total heap usage: 47 allocs, 37 frees, 7,132 bytes allocated
==31420==
==31420== 1,580 (1,440 direct, 140 indirect) bytes in 5 blocks are definitely lost in loss record 2 of 2
==31420== at 0x4C274A8: malloc (vg_replace_malloc.c:236)
==31420== by 0x400FD4: main (lab1.c:51)
==31420==
==31420== LEAK SUMMARY:
==31420== definitely lost: 1,440 bytes in 5 blocks
==31420== indirectly lost: 140 bytes in 5 blocks
==31420== possibly lost: 0 bytes in 0 blocks
==31420== still reachable: 0 bytes in 0 blocks
==31420== suppressed: 0 bytes in 0 blocks
==31420==
==31420== For counts of detected and suppressed errors, rerun with: -v
==31420== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)
我最后一次使用valgrind(几天前)除了堆和泄漏摘要之外,它会在出现错误消息时打印出来。
编辑: 我试过leak-check = full,结果相同
堆摘要(lab1.c:51)中提到的行是:
temp_record = malloc(sizeof(struct server_record));
我在代码中经常使用这个指针。这对于之前的valgrind错误消息非常有帮助,当我丢失指向这个malloc或其他问题的指针时,它们会告诉我。