C valgrind内存泄漏
嗨,我的Valgrind显示我记忆错误,但我无法找到它。
== 18608 ==总结:
== 18608 ==在退出时使用:1个块中有88个字节
== 18608 ==总堆使用情况:4个分配,3个空闲,分配2,220个字节
== == 18608
== 18608 ==搜索指向1个未释放块的指针
== 18608 ==检查53,708字节
== == 18608
== 18608 == 1个块中的88个字节绝对丢失在1的损失记录1中
== 18608 == 0x402D17C:malloc(在/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so中)
== 18608 == by 0x8 0485BF:pmalloc(in auf)
== 18608 == by 0x8048680:main(in auf)
== == 18608
== 18608 ==泄漏摘要:
== 18608 ==绝对丢失:1个块中88个字节
== 18608 ==间接丢失:0个字节0个字节
== 18608 ==可能丢失:0个字节0个字节
== 18608 ==仍然可以访问:0个字节0个字节
== 18608 ==被抑制:0个字节0个字节
== == 18608
== 18608 ==错误摘要:来自1个上下文的1个错误(被抑制:0从0)
== 18608 ==错误摘要:来自1个上下文的1个错误(被抑制:0从0)
你分配两个不同的int *
s; 你不会释放第一个资源,但是你可以释放第二个资源而不用做任何事情:
print_prim(pmalloc(n), laenge);
free(pmalloc(laenge));
要正确释放第一个资源,你可以这样做:
int *p = pmalloc(n);
print_prim(p, laenge);
free(p);
链接地址: http://www.djcxy.com/p/64955.html