From 3091dc72bc9fb3ef6253f21d64caa315b3ff7ab6 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Thu, 19 Sep 2024 15:30:26 +0100 Subject: [PATCH] testsuite/list: resolve memory leaks Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/143 Signed-off-by: Lucas De Marchi --- testsuite/test-list.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/testsuite/test-list.c b/testsuite/test-list.c index 68729750..143379be 100644 --- a/testsuite/test-list.c +++ b/testsuite/test-list.c @@ -21,6 +21,11 @@ static int len(struct kmod_list *list) return count; } +static void kmod_list_remove_all(struct kmod_list *list) +{ + while (list) + list = kmod_list_remove(list); +} static int test_list_last(const struct test *t) { @@ -36,6 +41,8 @@ static int test_list_last(const struct test *t) last = kmod_list_last(list); assert_return(last->data == v[N - 1], EXIT_FAILURE); + kmod_list_remove_all(list); + return 0; } DEFINE_TEST(test_list_last, @@ -65,6 +72,8 @@ static int test_list_prev(const struct test *t) assert_return(p->data == v[i], EXIT_FAILURE); } + kmod_list_remove_all(list); + return 0; } DEFINE_TEST(test_list_prev, @@ -91,6 +100,8 @@ static int test_list_remove_n_latest(const struct test *t) i++; } + kmod_list_remove_all(list); + return 0; } DEFINE_TEST(test_list_remove_n_latest, @@ -114,6 +125,8 @@ static int test_list_remove_data(const struct test *t) kmod_list_foreach (l, list) assert_return(l->data != removed, EXIT_FAILURE); + kmod_list_remove_all(list); + return 0; } DEFINE_TEST(test_list_remove_data, @@ -150,6 +163,8 @@ static int test_list_append_list(const struct test *t) i++; } + kmod_list_remove_all(c); + return 0; } DEFINE_TEST(test_list_append_list, @@ -184,6 +199,8 @@ static int test_list_insert_before(const struct test *t) l = kmod_list_next(list, l); assert_return(l->data == v3, EXIT_FAILURE); + kmod_list_remove_all(list); + return 0; } DEFINE_TEST(test_list_insert_before, @@ -218,6 +235,8 @@ static int test_list_insert_after(const struct test *t) l = kmod_list_next(list, l); assert_return(l->data == v3, EXIT_FAILURE); + kmod_list_remove_all(list); + return 0; } DEFINE_TEST(test_list_insert_after, -- 2.47.3