From 86d206ba7bb29b18a5521b56284ad378e3c9c67f Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Sun, 5 Feb 2023 18:12:33 +0100 Subject: [PATCH] implemented node-type in why2_free --- src/core/lib/utils/memory.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/core/lib/utils/memory.c b/src/core/lib/utils/memory.c index 6bd1f82..feaa5e3 100644 --- a/src/core/lib/utils/memory.c +++ b/src/core/lib/utils/memory.c @@ -6,13 +6,15 @@ #include +#include #include #include +#include #include //LOCAL -const enum POINTER_TYPES +enum POINTER_TYPES { ALLOCATION, FOPEN, @@ -145,7 +147,20 @@ void why2_free(void *pointer) if (node != NULL) remove_node(node); //REMOVE FROM LIST IF FOUND - free(pointer); + switch (node -> type) //DEALLOCATE BY THE CORRECT WAY + { + case ALLOCATION: //STANDARD MALLOC, CALLOC OR REALLOC + free(pointer); + break; + + case FOPEN: //FOPEN OR FDOPEN + fclose(pointer); + break; + + case OPEN: //OPEN SYSTEM CALL + close(*((int*) pointer)); + break; + } } void why2_clean_memory(char *identifier)