free()时出错,为何如此?

void Transmatrix(matrix sample)

{
int psample, ptemp, col;
int* cnum, * cpos;
node temp;

temp = (node)calloc(sample->num, sizeof(struct Node));
cnum = (int*)calloc(sample->r + 1, sizeof(int));
cpos = (int*)calloc(sample->r + 1, sizeof(int));

for (psample = 0; psample < sample->num; psample++) {
    cnum[sample->front[psample].r]++;
}

for (col = 1; col <= sample->r; col++) {
    cpos[col] = cpos[col - 1] + cnum[col - 1];
}

for (psample = 0; psample < sample->num; psample++) {
    col = sample->front[psample].r;
    ptemp = cpos[col];

    temp[ptemp].data = sample->front[psample].data;
    temp[ptemp].l = sample->front[psample].r;
    temp[ptemp].r = sample->front[psample].l;

    cpos[ptemp]++;
}

free(sample->front);
sample->front = temp;

free(cpos);    //出错
free(cnum);

}
图片说明

https://blog.csdn.net/zwhsoul/article/details/80146669

可以在程序运行时分配更多的内存。主要的工具是malloc()函数,
该函数接受一个参数:所需的内存字节数。malloc()函数会找到合适的
空闲内存块,这样的内存是匿名的。也就是说, malloc()分配内存,
但是不会为其赋名。然而,它确实返回动态分配内存块的首字节地址。
因此,可以把该地址赋给一个指针变量,并使用指针访问这块内存。
因为char表示1字节malloc()的返回类型通常被定义为指向char的指针。
然而,从ANSI C标准开始,C使用一个新的类型:指向void的指针。该类型
相当于一个“通用指针”。malloc()函数可用于返回指向数组的指针、指向
结构的指针等,所以通常该函数的返回值会被强制转换为匹配的类型。
在ANSI C中,应该坚持使用强制类型转换,提高代码的可读性。