diff --git a/get_next_line.c b/get_next_line.c index 2a1f132..9168c99 100644 --- a/get_next_line.c +++ b/get_next_line.c @@ -81,10 +81,8 @@ char *get_next_line(int fd) num_bytes_read = 1; while (num_bytes_read != 0) { - // DONE: if newline found, if (ft_strchr(buffer, '\n')) { - // DONE: copy string until newline to new buffer, outbuf = malloc((ft_strchr(buffer, '\n') - buffer + 2)); if (outbuf == NULL) { @@ -94,10 +92,7 @@ char *get_next_line(int fd) return (NULL); } ft_strlcpy(outbuf, buffer, ft_strchr(buffer, '\n') - buffer + 2); - // DONE: shorten current buffer, - // buffer += ft_strchr(buffer, '\n') - buffer + 1; buffer = shorten_buffer(buffer); - // DONE: and return. free(read_buffer); return (outbuf); } @@ -110,13 +105,9 @@ char *get_next_line(int fd) return (NULL); } read_buffer[num_bytes_read] = '\0'; - // DONE: join with big buffer buffer = ft_strjoin_free_s1(buffer, read_buffer); if (buffer == NULL) - { - free(read_buffer); return (NULL); - } } free(read_buffer); outbuf = buffer; diff --git a/get_next_line_utils.c b/get_next_line_utils.c index 6dac14a..606f561 100644 --- a/get_next_line_utils.c +++ b/get_next_line_utils.c @@ -94,6 +94,7 @@ char *ft_strjoin_free_s1(char const *s1, char const *s2) if (out == NULL) { free((void *)s1); + free((void *)s2); return (NULL); } ft_strlcpy(out, s1, len);