minishell/src/utils/check_malloc.c
2025-02-26 16:17:07 +01:00

38 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* check_malloc.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 18:00:10 by whaffman #+# #+# */
/* Updated: 2025/02/20 18:01:08 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void check_malloc(t_minishell *msh, void *ptr)
{
t_list *new;
if (ptr == NULL)
{
error_msg("malloc", "can't allocate memory");
ft_lstclear(&(msh->freelist), free);
exit(1);
}
else
{
new = ft_lstnew(ptr);
if (new == NULL)
{
error_msg("malloc", "can't allocate memory");
ft_lstclear(&(msh->freelist), free);
exit(1);
}
else
ft_lstadd_front(&(msh->freelist), new);
}
}