diff --git a/Makefile b/Makefile index 7b496e7..96cf167 100644 --- a/Makefile +++ b/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 \ diff --git a/srcs/ft_calloc.c b/srcs/ft_calloc.c index 5c2ed9f..b84f0ee 100644 --- a/srcs/ft_calloc.c +++ b/srcs/ft_calloc.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 */ /* diff --git a/srcs/ft_get_next_line.c b/srcs/ft_get_next_line.c index 65e545c..8b21774 100644 --- a/srcs/ft_get_next_line.c +++ b/srcs/ft_get_next_line.c @@ -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) diff --git a/srcs/ft_lstadd_back.c b/srcs/ft_lstadd_back.c index 37084d1..315119b 100644 --- a/srcs/ft_lstadd_back.c +++ b/srcs/ft_lstadd_back.c @@ -86,6 +86,5 @@ void ft_lstadd_back(t_list **alst, t_list *new) tmp = tmp->next; tmp->next = new; } - new->next = NULL; } } diff --git a/srcs/ft_lstdelone.c b/srcs/ft_lstdelone.c index 3ff3259..0cf925a 100644 --- a/srcs/ft_lstdelone.c +++ b/srcs/ft_lstdelone.c @@ -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; } diff --git a/srcs/ft_strjoinfree.c b/srcs/ft_strjoinfree.c index 394455d..66c8b50 100644 --- a/srcs/ft_strjoinfree.c +++ b/srcs/ft_strjoinfree.c @@ -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); }