implemented node-type in why2_free

This commit is contained in:
Václav Šmejkal 2023-02-05 18:12:33 +01:00
parent 2422079bba
commit 86d206ba7b
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -6,13 +6,15 @@
#include <why2/memory.h> #include <why2/memory.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <why2/flags.h> #include <why2/flags.h>
//LOCAL //LOCAL
const enum POINTER_TYPES enum POINTER_TYPES
{ {
ALLOCATION, ALLOCATION,
FOPEN, FOPEN,
@ -145,7 +147,20 @@ void why2_free(void *pointer)
if (node != NULL) remove_node(node); //REMOVE FROM LIST IF FOUND if (node != NULL) remove_node(node); //REMOVE FROM LIST IF FOUND
switch (node -> type) //DEALLOCATE BY THE CORRECT WAY
{
case ALLOCATION: //STANDARD MALLOC, CALLOC OR REALLOC
free(pointer); 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) void why2_clean_memory(char *identifier)