gnl leak fix

This commit is contained in:
Jack Halford 2017-02-17 14:03:55 +01:00
parent dc01b777e1
commit 6e70998249
2 changed files with 11 additions and 3 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/15 13:12:06 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); 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) static t_list *ft_newfd(t_list **head, int fd)
{ {
t_save new; t_save new;
@ -60,6 +65,7 @@ int get_next_line(int const fd, char **line)
t_list *tmp; t_list *tmp;
char *pos; char *pos;
char *save; char *save;
int ret;
if (fd < 0 || !line) if (fd < 0 || !line)
return (-1); return (-1);
@ -75,5 +81,7 @@ int get_next_line(int const fd, char **line)
*pos = 0; *pos = 0;
return (1); 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);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:12 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */