From e4bfe3c7d10bcb277178065ee71423661acedab1 Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Fri, 14 Jul 2017 17:53:56 +0100 Subject: [PATCH] Free all the data structures associated with test cases. Removes some of the memory leaks discovered by AddressSanitizer in the test suite (see Issue #23) --- expat/tests/minicheck.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/expat/tests/minicheck.c b/expat/tests/minicheck.c index 9003d3b7..1b803c22 100644 --- a/expat/tests/minicheck.c +++ b/expat/tests/minicheck.c @@ -70,6 +70,24 @@ tcase_add_test(TCase *tc, tcase_test_function test) tc->ntests++; } +static void +tcase_dispose(TCase *tc) +{ + free(tc->tests); + free(tc); +} + +static void +suite_dispose(Suite *suite) +{ + while (suite->tests != NULL) { + TCase *next = suite->tests->next_tcase; + tcase_dispose(suite->tests); + suite->tests = next; + } + free(suite); +} + SRunner * srunner_create(Suite *suite) { @@ -175,6 +193,6 @@ srunner_ntests_failed(SRunner *runner) void srunner_free(SRunner *runner) { - free(runner->suite); + suite_dispose(runner->suite); free(runner); }