我在使用此功能时遇到问题:
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)行崩溃了; ..我想我做得很好,没有任何错误。也许是内存问题,解决方案很简单,但我真的找不到它^^只要告诉我您是否需要更多信息,或者我不太清楚。很抱歉我的“ maccheroni english”:P。
在此先感谢伙计们!
最佳答案
如果您在未分配的内存地址上调用free,则它将崩溃。用这个:
if(tmp != NULL) free(tmp);
关于c - Free()语句会崩溃吗?帮助此功能解决:(,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27962836/