【发布时间】:2018-10-11 11:38:37
【问题描述】:
当我通过向我的代码添加泄漏来运行 valgrind 时,我发现泄漏对于第一次分配块仍然可以访问,然后显示为肯定丢失了 9 个块。可能由于代码的其他部分而丢失。为什么会这样?
main()
{
........
char *ptr;
For(i=0;i<10;i++)
{
ptr=malloc(sizeof * ptr);
}
.....
}
报告:
HEAP SUMMARY:
==13832== in use at exit: 202,328 bytes in 62 blocks
==13832== total heap usage: 332 allocs, 270 frees, 283,928 bytes allocated
==13832==
==13832== LEAK SUMMARY:
==13832== definitely lost: 90 bytes in 9 blocks
==13832== indirectly lost: 0 bytes in 0 blocks
==13832== possibly lost: 202,180 bytes in 49 blocks
==13832== still reachable: 58 bytes in 4 blocks
==13832== suppressed: 0 bytes in 0 blocks
==13832== Rerun with --leak-check=full to see details of leaked memory
【问题讨论】:
标签: memory-leaks valgrind