From: Rhodri James Date: Fri, 14 Jul 2017 16:53:56 +0000 (+0100) Subject: Free all the data structures associated with test cases. X-Git-Tag: R_2_2_3~32^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e4bfe3c7d10bcb277178065ee71423661acedab1;p=libexpat 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) --- 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); }