C valgrind memory leakage

Hi my Valgrind shows me memory error but I cant find it.

==18608== HEAP SUMMARY:

==18608== in use at exit: 88 bytes in 1 blocks

==18608== total heap usage: 4 allocs, 3 frees, 2,220 bytes allocated

==18608==

==18608== Searching for pointers to 1 not-freed blocks

==18608== Checked 53,708 bytes

==18608==

==18608== 88 bytes in 1 blocks are definitely lost in loss record 1 of 1

==18608== at 0x402D17C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)

==18608== by 0x8 0485BF: pmalloc (in auf)

==18608== by 0x8048680: main (in auf)

==18608==

==18608== LEAK SUMMARY:

==18608== definitely lost: 88 bytes in 1 blocks

==18608== indirectly lost: 0 bytes in 0 blocks

==18608== possibly lost: 0 bytes in 0 blocks

==18608== still reachable: 0 bytes in 0 blocks

==18608== suppressed: 0 bytes in 0 blocks

==18608==

==18608== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

==18608== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)


You allocate two different int * s; you don't free the first resource but you free the second one without doing anything with it:

print_prim(pmalloc(n), laenge);
free(pmalloc(laenge));

To free the first resource properly, you would do something like this:

int *p = pmalloc(n);
print_prim(p, laenge);
free(p);
链接地址: http://www.djcxy.com/p/64956.html

上一篇: Valgrind没有检测到危险的释放记忆

下一篇: C valgrind内存泄漏