fixed remove_node_from_end memory leak
This commit is contained in:
parent
5879c02d77
commit
5c2f77f14f
@ -69,18 +69,23 @@ void remove_node_from_end(void)
|
|||||||
if (list_head == NULL) return; //EMPTY LIST
|
if (list_head == NULL) return; //EMPTY LIST
|
||||||
|
|
||||||
node_t *buffer = list_head;
|
node_t *buffer = list_head;
|
||||||
|
node_t *deallocating_node;
|
||||||
|
|
||||||
if (buffer -> next == NULL) //ONLY ONE NODE
|
if (buffer -> next == NULL) //ONLY ONE NODE
|
||||||
{
|
{
|
||||||
|
deallocating_node = buffer;
|
||||||
|
|
||||||
list_head = NULL;
|
list_head = NULL;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
while (buffer -> next -> next != NULL) buffer = buffer -> next; //GO TO THE NODE BEFORE END
|
while (buffer -> next -> next != NULL) buffer = buffer -> next; //GO TO THE NODE BEFORE END
|
||||||
|
|
||||||
|
deallocating_node = buffer -> next;
|
||||||
|
|
||||||
buffer -> next = NULL; //UNLINK
|
buffer -> next = NULL; //UNLINK
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buffer -> next);
|
free(deallocating_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_last_node_identifier(void)
|
char *get_last_node_identifier(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user