1. Error Description: A node function that deletes a single-linked list has just been written, and the parameter is a pointer to a list of pointers and nodes in the linked list that specify the deletions. When I free the node to be deleted, the result is an error.
2. Why did you get an error?
I checked MSDN and I saw "attepmting to free" Invalid pointer (a pointer to a memory block, which was not allocated by Calloc , malloc, or realloc) may affect subsequent allocation requests and cause errors ". It means that only free memory can be dropped by Calloc,malloc, realloc application. And I'm trying to release the memory that the defined node occupies.
3. Error codes
Statusdelete (structNODE **ROOTP,structNODE *node) {Pnode P_node=NULL; if(ROOTP = =NULL) {printf ("no actionable list \ n" ); returnFALSE; } if(node = =NULL) {printf ("no node specified for deletion \ n" ); returnFALSE; } if(Node = = *ROOTP) { *ROOTP = node->next;/*Delete the first node.*/ }Else{ for(P_node = *ROOTP; P_node! = NULL && P_node->next! =node; P_node= p_node->next); if(P_node = =NULL) {printf ("specifies that the deleted node does not exist \ n" ); returnFALSE; }Else{P_node->next = node->next;/*Delete an intermediate or trailing node.*/ } } /*here's the problem.*/ Free(node); Node=NULL; returnTRUE;}/*Main function*/voidMain () {Pnode list= (Pnode)malloc(sizeof(structNODE)); Pnode P=NULL; Node One, three, four; One.data=1; Two.data=2; Three.data=3; Four.data=4; One.next= &both ; Two.next= &three; Three.next= &Four ; Four.next=NULL; List->next = &One ; P= &three; if(Delete (&list, p) = =TRUE) {Put (list); }Else{printf ("Delete failed \ n" ); }}
Free an invalid pointer