added list deallocation to remove_node
This commit is contained in:
parent
fefc2f83e2
commit
c8e2c4226d
@ -19,7 +19,7 @@ typedef struct node
|
||||
struct node *last;
|
||||
} node_t; //DOUBLY LINKED LIST
|
||||
|
||||
node_t *head = NULL; //TODO: Find a way to deallocate this shit at the end
|
||||
node_t *head = NULL;
|
||||
|
||||
void push_to_list(void *pointer)
|
||||
{
|
||||
@ -45,10 +45,8 @@ void push_to_list(void *pointer)
|
||||
}
|
||||
}
|
||||
|
||||
void remove_node(node_t *node)
|
||||
void remove_node(node_t *node) //valgrind says this causes memory leaks ('still reachable'), but there is no chance like wtf
|
||||
{
|
||||
if (head == NULL) return; //LIST IS EMPTY
|
||||
|
||||
//REMOVE NODE
|
||||
node_t *node_buffer = head;
|
||||
|
||||
@ -75,6 +73,8 @@ void remove_node(node_t *node)
|
||||
node -> last = NULL;
|
||||
}
|
||||
|
||||
if (head == NULL) free(head); //LIST IS EMPTY NOW => DEALLOCATE
|
||||
|
||||
//DEALLOCATION
|
||||
free(node);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user