我在使用此功能时遇到问题:
struct list{
int x;
int y;
struct list *next_ptr;
};
boolean funzione_esame(struct list **ptrptr, int *number){
if(*ptrptr != NULL){
struct list *tmp;
struct list *pos;
pos=(*ptrptr)->next_ptr;
*number=1;
while(pos != NULL){
if(pos->x <= (*ptrptr)->y){
pos->x=(*ptrptr)->y;
if(pos->x >= pos->y){
tmp=pos;
pos=pos->next_ptr;
free(tmp);
continue;
}
}
pos=pos->next_ptr;
ptrptr=&((*ptrptr)->next_ptr);
(*number)++;
}
return TRUE;
} else return FALSE;
}
我不会浪费时间向你解释它应该做什么等等。但我只是不明白为什么它会在 free(tmp); 行崩溃。
我认为我做得很好,没有任何类型的错误。也许这是一个内存问题,解决方案很简单,但我真的找不到它^^
如果您需要更多信息或者我不是很清楚,请告诉我。对我的“通心粉英语”感到抱歉:P。
提前感谢各位!
最佳答案
如果你在未分配的内存地址上调用 free ,那么它就会崩溃。使用这个:
if(tmp != NULL) free(tmp);
关于c - Free() 语句崩溃?帮助这个函数解决:(,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27962836/