ft_lstclear fonctionne avec une function dell null, joinfree free les deux elements, gnl dup l'element qui sera free par joinfree

This commit is contained in:
hugogogo
2021-06-27 13:31:43 +02:00
parent f1ce5b8b9e
commit 26147eeeeb
6 changed files with 9 additions and 8 deletions

View File

@@ -12,7 +12,7 @@ _DEP = libft.h
DEPS = $(_DEP:%.h=$(IDIR)/%.h)
CFLAGS = -I$(IDIR)
CFLAGS += -Wall -Wextra -Werror
CFLAGS += -Wall -Wextra -Werror -g3
SRCS = ft_memset.c \
ft_bzero.c \

View File

@@ -11,13 +11,13 @@
/* ************************************************************************** */
/*
** allocate count * size byte of memory and
** return a pointer to the allocated memory
**
** exemple allocation for 5 integers with malloc then calloc :
** a = (int *)malloc(5 * sizeof(int)); //5*4bytes = 20 bytes
** free(a);
** a = (int *)calloc(5, sizeof(int));
**
** allocate count * size byte of memory and
** return a pointer to the allocated memory
*/
/*

View File

@@ -123,7 +123,7 @@ int get_next_line(const int fd, char **line)
if ((ret = read(fd, buf, BUFFER_SIZE)) < 0)
return (free_lst(&lst, -1));
buf[ret] = '\0';
if (!(lst->str = ft_strjoinfree(lst->str, buf)))
if (!(lst->str = ft_strjoinfree(lst->str, ft_strdup(buf))))
return (free_lst(&lst, -1));
}
if (str != NULL)

View File

@@ -86,6 +86,5 @@ void ft_lstadd_back(t_list **alst, t_list *new)
tmp = tmp->next;
tmp->next = new;
}
new->next = NULL;
}
}

View File

@@ -90,7 +90,8 @@
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
del(lst->content);
if (lst->content && del)
del(lst->content);
free(lst);
lst = NULL;
}

View File

@@ -12,7 +12,7 @@
/*
** create a new string by concatenating the two strings s1 and s2
** then free s1
** then free s1 and s2
*/
#include "libft.h"
@@ -24,5 +24,6 @@ char *ft_strjoinfree(char *s1, char *s2)
if (!(str = ft_strjoin(s1, s2)))
return (NULL);
free(s1);
free(s2);
return (str);
}