C 如何修复双重释放或损坏
这是我的代码的一部分,用于删除循环链表的节点。在运行程序时,它会给出正确的输出,但表示双重自由或损坏(fasttop)。我该如何解决这个问题C 如何修复双重释放或损坏,c,linked-list,C,Linked List,这是我的代码的一部分,用于删除循环链表的节点。在运行程序时,它会给出正确的输出,但表示双重自由或损坏(fasttop)。我该如何解决这个问题 void deleter(struct Node ** head, int deletespace, int length){ struct Node * current = *head; int delete_counter = 0; while(delete_counter < length-1){
void deleter(struct Node ** head, int deletespace, int length){
struct Node * current = *head;
int delete_counter = 0;
while(delete_counter < length-1){
/*to count for skipping/not eliminating the first k-1 contestents */
for (int i = 1; i < deletespace-1 ; i++){
current = current->next;
}
/*assigns the position of the content to be eliminated to p*/
struct Node * p = current->next;
/*moves the counter to the k+1 contestent*/
current->next = p->next;
/*eliminated the contestent*/
free(p);
p == NULL;
current = current->next;
delete_counter++;
}
printf("%d\n", current->info) ;
free(current);
current == NULL;
}
void deleter(结构节点**head,int deletespace,int length){
结构节点*当前=*头部;
int delete_计数器=0;
while(删除计数器下一步;
}
/*将要删除的内容的位置指定给p*/
结构节点*p=当前->下一步;
/*将计数器移到k+1竞争点*/
当前->下一步=p->下一步;
/*淘汰了竞争对手*/
自由基(p);
p==NULL;
当前=当前->下一步;
删除_计数器++;
}
printf(“%d\n”,当前->信息);
自由(电流);
当前==NULL;
}
此行不执行任何操作:p==NULL代码>也许你的意思是p=NULL代码>?@christiangibonsp=NULL代码>也不会做任何事情,因为这是一个在free()之后不使用的局部变量代码>有意义结合免费(p)代码>?看起来你想要这两个中的任何一个,但不是同时想要两个?@Lundin,这很公平。在我看到那条可疑的线后,我并没有再进一步挖掘。事实证明,这是一个愚蠢的错误。它确实是“p=NULL”和“current=NULL”,而不是使用==@ChristianGibbons,你是对的哈哈哈,谢谢你的帮助!此行不做任何操作:p==NULL代码>也许你的意思是p=NULL代码>?@christiangibonsp=NULL代码>也不会做任何事情,因为这是一个在free()之后不使用的局部变量代码>有意义结合免费(p)代码>?看起来你想要这两个中的任何一个,但不是同时想要两个?@Lundin,这很公平。在我看到那条可疑的线后,我并没有再进一步挖掘。事实证明,这是一个愚蠢的错误。它确实是“p=NULL”和“current=NULL”,而不是使用==@ChristianGibbons,你是对的哈哈哈,谢谢你的帮助!