结构体指针的释放问题!
typedef struct A
{
int d;
int alpha;
int height;
int width;
int *buf;
}A;
typedef struct B
{
int dnum;
int alphanum;
int Tempnum;
A SFT[12]; //dnum*alphanum=Tempnum
}B;
代码如上,定义了两个模板,其中B模板中有A类型的数组变量,可是最后释放的时候要如何释放每个buf 呢?
void main()
{
B *temp;
initfunction(&temp);
freefunction(&temp);
}
void freefunction(B **temp)
{
for(int k=0;k<12;k++)
{
free((*temp)->SFT[k].buf);//////////////////////内存错误
(*temp)->SFT[k].buf=NULL;
}
}
这样运行的话,到free函数时会报内存错误,是不是结构体B里面不能定义数组变量?具体应该如何释放buf??跪求指导!