only 7bytes of leaks
This commit is contained in:
parent
df151381bc
commit
386bef0a64
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/26 00:52:47 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/26 16:39:09 by cchauvet ### ########.fr */
|
||||
/* Updated: 2022/10/28 13:37:18 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,7 +17,7 @@ char *ft_getstash(int fd)
|
||||
char *str;
|
||||
int readed;
|
||||
|
||||
str = ft_calloc(BUFFER_SIZE, sizeof(char));
|
||||
str = ft_calloc(BUFFER_SIZE + 1, sizeof(char));
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
readed = read(fd, str, BUFFER_SIZE);
|
||||
@ -50,6 +50,7 @@ char *ft_getline(int fd)
|
||||
size_t i;
|
||||
|
||||
stash = NULL;
|
||||
buf = NULL;
|
||||
i = 0;
|
||||
while (ft_strchr(stash + i, '\n') == -1)
|
||||
{
|
||||
@ -75,19 +76,19 @@ char *get_next_line(int fd)
|
||||
char *buf1;
|
||||
char *buf2;
|
||||
|
||||
buf2 = stash;
|
||||
if (ft_strchr(stash, '\n') == -1)
|
||||
{
|
||||
buf1 = ft_getline(fd);
|
||||
if (buf1 == NULL)
|
||||
return (NULL);
|
||||
stash = ft_strfjoin(stash, buf1);
|
||||
if (stash == NULL)
|
||||
buf2 = ft_strfjoin(stash, buf1);
|
||||
if (buf2 == NULL)
|
||||
return (NULL);
|
||||
}
|
||||
buf1 = ft_strndup(stash, ft_strchr(stash, '\n') + 1);
|
||||
buf2 = ft_strndup(stash + ft_strchr(stash, '\n') + 1, ft_strlen(stash));
|
||||
free(stash);
|
||||
stash = buf2;
|
||||
buf1 = ft_strndup(buf2, ft_strchr(buf2, '\n') + 1);
|
||||
stash = ft_strndup(buf2 + ft_strchr(buf2, '\n') + 1, ft_strlen(buf2));
|
||||
free(buf2);
|
||||
if (stash == NULL || buf1 == NULL)
|
||||
{
|
||||
free(stash);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/26 00:55:44 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/26 16:33:23 by cchauvet ### ########.fr */
|
||||
/* Updated: 2022/10/26 23:55:03 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -30,32 +30,6 @@ void *ft_calloc(size_t nmemb, size_t size)
|
||||
}
|
||||
return ((void *) tab);
|
||||
}
|
||||
|
||||
void *ft_realloc(void *ptr, size_t size)
|
||||
{
|
||||
char *tab;
|
||||
char *in;
|
||||
size_t i;
|
||||
|
||||
in = ptr;
|
||||
tab = ft_calloc(sizeof(char), size);
|
||||
if (tab == NULL)
|
||||
return (NULL);
|
||||
if (ptr == NULL)
|
||||
{
|
||||
free(ptr);
|
||||
return (tab);
|
||||
}
|
||||
i = 0;
|
||||
while (in[i] != 0 && i < size)
|
||||
{
|
||||
tab[i] = in[i];
|
||||
i++;
|
||||
}
|
||||
free(ptr);
|
||||
return (tab);
|
||||
}
|
||||
|
||||
size_t ft_strlen(char *str)
|
||||
{
|
||||
size_t i;
|
||||
@ -88,10 +62,13 @@ char *ft_strfjoin(char *s1, char *s2)
|
||||
}
|
||||
free(s1);
|
||||
j = 0;
|
||||
while (s2[j] != '\0')
|
||||
if (s2 != NULL)
|
||||
{
|
||||
out[i + j] = s2[j];
|
||||
j++;
|
||||
while (s2[j] != '\0')
|
||||
{
|
||||
out[i + j] = s2[j];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
free(s2);
|
||||
return (out);
|
||||
|
1
gnlTester
Submodule
1
gnlTester
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 2e28a6ce9454666c6670645a60a1b9b4404d0c65
|
9
main.c
9
main.c
@ -7,7 +7,14 @@
|
||||
int main(void)
|
||||
{
|
||||
int fd = open("tester", O_RDONLY);
|
||||
char *str = get_next_line(fd);
|
||||
char *str;
|
||||
str = get_next_line(fd);
|
||||
printf("%s", str);
|
||||
free(str);
|
||||
str = get_next_line(fd);
|
||||
printf("%s", str);
|
||||
free(str);
|
||||
str = get_next_line(fd);
|
||||
printf("%s", str);
|
||||
free(str);
|
||||
// printf("%s", get_next_line(fd));
|
||||
|
Loading…
Reference in New Issue
Block a user