fixed why2_clean_memory memory leak

I was trying to use deallocated node, so yeah
This commit is contained in:
Václav Šmejkal 2023-02-08 10:32:03 +01:00
parent a2492aa124
commit 34a387f032
Signed by: ENGO150
GPG Key ID: F6D6DF86242C5A59

View File

@ -199,13 +199,20 @@ void why2_clean_memory(char *identifier)
if (head == NULL) return; //LIST IS EMPTY if (head == NULL) return; //LIST IS EMPTY
node_t *buffer = head; node_t *buffer = head;
void *pointer_buffer = NULL;
why2_bool force_deallocating = identifier == why2_get_default_memory_identifier(); why2_bool force_deallocating = identifier == why2_get_default_memory_identifier();
while (buffer -> next != NULL) //GO TROUGH LIST 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; 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 if (buffer -> identifier == identifier || force_deallocating) why2_deallocate(buffer -> pointer); //LAST NODE