From 6e709982494dce987b5e48292def6138fdff2964 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 17 Feb 2017 14:03:55 +0100 Subject: [PATCH] gnl leak fix --- libft/src/get_next_line/get_next_line.c | 12 ++++++++++-- libft/src/lst/ft_lst_delif.c | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libft/src/get_next_line/get_next_line.c b/libft/src/get_next_line/get_next_line.c index cc5f6145..b66db533 100644 --- a/libft/src/get_next_line/get_next_line.c +++ b/libft/src/get_next_line/get_next_line.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/15 13:12:06 by jhalford #+# #+# */ -/* Updated: 2016/12/15 13:00:23 by jhalford ### ########.fr */ +/* Updated: 2017/02/17 14:03:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,11 @@ static int ft_fdcmp(t_save *a, int *b) return (a->fd - *b); } +static int ft_gnlfree(t_save *a, size_t size) +{ + ft_strdel(&a->str); +} + static t_list *ft_newfd(t_list **head, int fd) { t_save new; @@ -60,6 +65,7 @@ int get_next_line(int const fd, char **line) t_list *tmp; char *pos; char *save; + int ret; if (fd < 0 || !line) return (-1); @@ -75,5 +81,7 @@ int get_next_line(int const fd, char **line) *pos = 0; return (1); } - return (ft_loop_read(fd, line, save)); + if (!(ret = ft_loop_read(fd, line, save))) + ft_lst_delif(&head, &fd, ft_fdcmp, ft_gnlfree); + return (ret); } diff --git a/libft/src/lst/ft_lst_delif.c b/libft/src/lst/ft_lst_delif.c index c331835b..7c195b35 100644 --- a/libft/src/lst/ft_lst_delif.c +++ b/libft/src/lst/ft_lst_delif.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */ -/* Updated: 2017/01/11 16:26:31 by jhalford ### ########.fr */ +/* Updated: 2017/02/17 13:59:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */