我无法弄清楚为什么我在以下代码中出现肯定丢失的错误。我已将 main 函数中的 return 0 更改为 exit (0) 但没有帮助。
struct s* function(int K,struct graph *G,int c){
uint32_t *a;
a=(uint32_t*)calloc(K+2,sizeof(uint32_t));
int *b;
b=(uint32_t*)calloc(K+2,sizeof(uint32_t));
return s;
}
int main(int argc, char *argv[])
{
struct S* s=function(K,Gprime,capacity);
return 0;
}
下面你可以看到S结构代码:
struct S{
int *S;
uint32_t *Scount;
};
struct S* Sp(int s,int k){
struct S* sz =malloc(sizeof (struct S));
sz->S = (int*)calloc(s+1, sizeof(int));
sz->scount=(uint32_t*)calloc(k+1,sizeof(uint32_t));
return sz;
}
这是 valgrind 错误:
==5343== 680 bytes in 5 blocks are definitely lost in loss record 10 of 52
==5343== at 0x4C272B8: calloc (vg_replace_malloc.c:566)
==5343== by 0x40106B: function (reflowk.c:3)
==5343== by 0x402BB0: main (reflowk.c:9)
最佳答案
您必须调用free()
释放 malloc
保留的内存和calloc
当您使用完该内存后。
关于c - valgrind 肯定丢失了 block 调用功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44927069/