heap-use-after-free 关于删除链表节点
为什么图中这一行加入后就会报错
把malloc那行去掉也是报错
struct ListNode* deleteDuplicates(struct ListNode* head){
int i;
struct ListNode* list = malloc(sizeof(struct ListNode));
list = head ;
if(list == NULL)
return head;
while(list->next != NULL){
if(list->next->val == list ->val){
list->next = list->next->next;
// struct ListNode* p = malloc(sizeof(struct ListNode));
struct ListNode* p= list -> next;
free();
}
else{
list = list->next;
}
}
return head;
} 本帖最后由 jhq999 于 2022-4-3 08:02 编辑
struct ListNode* deleteDuplicates(struct ListNode* head){
//int i;
//struct ListNode* list = malloc(sizeof(struct ListNode));
struct ListNode *list = head ;
if(list == NULL)
return head;
while(list->next != NULL){
if(list->next->val == list ->val){
struct ListNode* p= list -> next;
list->next = list->next->next;
free(p);
}
else
list = list->next;
}
return head;
} 1
页:
[1]