fix: test leak

This commit is contained in:
starnakin 2024-09-11 20:20:49 +02:00
parent 3effb7caf5
commit ebf0b0e442
2 changed files with 5 additions and 2 deletions

View File

@ -24,7 +24,7 @@ all : $(NAME)
test : $(NAME) test : $(NAME)
$(CC) $(CFLAGS) test/test.c $(BUILDDIR)/$(NAME) -o $(BUILDDIR)/test $(CC) $(CFLAGS) test/test.c $(BUILDDIR)/$(NAME) -o $(BUILDDIR)/test
$(BUILDDIR)/test valgrind --leak-check=full $(BUILDDIR)/test
clean : clean :
rm -rf $(OBJDIR) rm -rf $(OBJDIR)

View File

@ -84,7 +84,8 @@ void destroy_list(t_list *root, void *(destroy_data)(void *))
{ {
prev = current; prev = current;
if (current->data) if (current->data)
destroy_data(current->data); if (destroy_data)
destroy_data(current->data);
current = current->next; current = current->next;
free(prev); free(prev);
} }
@ -134,6 +135,7 @@ void multiple_test_list_size()
if (root == NULL) if (root == NULL)
return; return;
test_int(len, ft_list_size(root)); test_int(len, ft_list_size(root));
destroy_list(root, NULL);
printf("\n"); printf("\n");
} }
} }
@ -160,6 +162,7 @@ void multiple_test_push_front()
printf(" list-size: "); printf(" list-size: ");
test_int(len + 1, ft_list_size(root)); test_int(len + 1, ft_list_size(root));
printf("\n"); printf("\n");
destroy_list(root, NULL);
} }
} }