我想动态地分配内存中的函数结构指针的数组。它的工作原理,直到3次迭代,但坠毁与此错误后:一些迭代后Realloc腐败C
double free or corruption (fasttop): ...
这里是我的结构指针数组声明:
Intersection** alreadyUse = malloc(sizeof(Intersection*));
if(alreadyUse == NULL) {
exit(1);
}
int size = 1;
alreadyUse[0] = inter; // Pointer of an Intersection
// Some Code
checkFunction(alreadyUse, &size, interLeft);
这是我的功能
bool checkFunction(Intersection** alreadyUse, int* size, Intersection* inter) {
for(int i = 0; i < *size; i++) {
if(alreadyUse[i] == inter) {
return true;
}
}
*size = *size +1;
Intersection** tmp = realloc(alreadyUse, sizeof(Intersection*) * *size);
if(tmp == NULL){
exit(1);
}
else {
alreadyUse = tmp;
}
alreadyUse[*size-1] = inter;
return false;
}
正如我所说的,它适用于1,2,3,然后我得到错误。
有人有一个想法,为什么它的作品,然后突然崩溃?
感谢您的帮助。
我们不知道交集类型 –