From c8e2c4226d5ad9d127120bc3eb2b628bf98f6e46 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Tue, 31 Jan 2023 19:03:02 +0100 Subject: [PATCH] added list deallocation to remove_node --- src/core/lib/utils/memory.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/lib/utils/memory.c b/src/core/lib/utils/memory.c index d5d1c60..6769b2b 100644 --- a/src/core/lib/utils/memory.c +++ b/src/core/lib/utils/memory.c @@ -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); }