added list deallocation to remove_node

This commit is contained in:
Václav Šmejkal 2023-01-31 19:03:02 +01:00
parent fefc2f83e2
commit c8e2c4226d
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -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);
}