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:
2
Makefile
2
Makefile
@@ -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 \
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -86,6 +86,5 @@ void ft_lstadd_back(t_list **alst, t_list *new)
|
||||
tmp = tmp->next;
|
||||
tmp->next = new;
|
||||
}
|
||||
new->next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user