From 5c2f77f14f5d24353648be6e3656eb15e814ac23 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Sat, 4 Feb 2023 18:44:08 +0100 Subject: [PATCH] fixed remove_node_from_end memory leak --- src/core/lib/flags.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/lib/flags.c b/src/core/lib/flags.c index 5b340c9..731f3a6 100644 --- a/src/core/lib/flags.c +++ b/src/core/lib/flags.c @@ -69,18 +69,23 @@ void remove_node_from_end(void) if (list_head == NULL) return; //EMPTY LIST node_t *buffer = list_head; + node_t *deallocating_node; if (buffer -> next == NULL) //ONLY ONE NODE { + deallocating_node = buffer; + list_head = NULL; } else { while (buffer -> next -> next != NULL) buffer = buffer -> next; //GO TO THE NODE BEFORE END + deallocating_node = buffer -> next; + buffer -> next = NULL; //UNLINK } - free(buffer -> next); + free(deallocating_node); } char *get_last_node_identifier(void)