minishell/src/utils/free_safe.c
2025-02-25 18:31:14 +01:00

48 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* free_safe.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/25 15:09:34 by whaffman #+# #+# */
/* Updated: 2025/02/25 18:06:06 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
void free_safe(t_minishell *minishell, void **ptr)
{
t_list *prev;
t_list *current;
prev = NULL;
current = minishell->freelist;
if (*ptr)
{
while (current)
{
if (current->content == *ptr)
{
if (prev)
prev->next = current->next;
else
minishell->freelist = current->next;
free(*ptr);
free(current);
return ;
}
prev = current;
current = current->next;
}
error_msg("free_safe", "pointer not found in freelist");
}
*ptr = NULL;
}