fix leak in list_remove_if

This commit is contained in:
2025-04-12 20:49:55 +02:00
parent 5d98a06bf4
commit 5f5ea11549
2 changed files with 42 additions and 26 deletions

24
test.c
View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/29 19:53:58 by tomoron #+# #+# */
/* Updated: 2025/04/12 19:08:05 by tomoron ### ########.fr */
/* Updated: 2025/04/12 19:30:05 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,6 +38,12 @@
fail++;\
}
void remove_if_free(void *data)
{
printf("%ld\n", (long int) data);
}
int test_strlen(void)
{
int fail = 0;
@ -65,7 +71,6 @@ int test_strcpy(void)
return(fail);
}
int test_strcmp(void)
{
int fail = 0;
@ -234,6 +239,11 @@ int test_list_sort()
ft_list_sort(0, 0);
TEST("null pointer (should not segfault)", 1);
free(tmp->next->next->next);
free(tmp->next->next);
free(tmp->next);
free(tmp);
return(fail);
}
@ -242,11 +252,6 @@ int remove_if_compare(void *data, int *nb)
return((long)data == *nb);
}
void remove_if_free(void *data)
{
printf("%ld\n", (long int) data);
}
int test_list_remove_if()
{
int fail = 0;
@ -268,6 +273,9 @@ int test_list_remove_if()
ft_list_remove_if(&tmp, &nb, remove_if_compare, 0);
TEST("null pointers in functions", 1);
free(tmp->next);
free(tmp);
return(fail);
}
@ -294,5 +302,5 @@ int main(void)
printf("\n\n");
FNC_TEST("ft_list_sort", test_list_sort());
printf("\n\n");
FNC_TEST("ft_list_sort", test_list_remove_if());
FNC_TEST("ft_list_remove_if", test_list_remove_if());
}