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)
This commit is contained in:
Rhodri James 2017-07-14 17:53:56 +01:00
parent 38c1ce7cd5
commit e4bfe3c7d1

View File

@ -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);
}