From 34a387f0320035ba61e5cabab8bede60eb625802 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Wed, 8 Feb 2023 10:32:03 +0100 Subject: [PATCH] fixed why2_clean_memory memory leak I was trying to use deallocated node, so yeah --- src/core/lib/utils/memory.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/lib/utils/memory.c b/src/core/lib/utils/memory.c index 7ce0535..ec51324 100644 --- a/src/core/lib/utils/memory.c +++ b/src/core/lib/utils/memory.c @@ -199,13 +199,20 @@ void why2_clean_memory(char *identifier) if (head == NULL) return; //LIST IS EMPTY node_t *buffer = head; + void *pointer_buffer = NULL; why2_bool force_deallocating = identifier == why2_get_default_memory_identifier(); while (buffer -> next != NULL) //GO TROUGH LIST { - if (buffer -> identifier == identifier || force_deallocating) why2_deallocate(buffer -> pointer); + if (buffer -> identifier == identifier || force_deallocating) pointer_buffer = buffer -> pointer; buffer = buffer -> next; + + if (pointer_buffer != NULL) + { + why2_deallocate(pointer_buffer); + pointer_buffer = NULL; + } } if (buffer -> identifier == identifier || force_deallocating) why2_deallocate(buffer -> pointer); //LAST NODE