summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki@daynix.com>2024-06-26 20:01:01 +0900
committerAkihiko Odaki <akihiko.odaki@daynix.com>2024-06-26 20:02:18 +0900
commit0e994ead0f8d4335cd6e52205a2d7446b171e2ae (patch)
tree50c1c690302f48c9e9a6961966dfa79ebdd71781
parent07fa7b261c4749b2edda5a95bcf7d12d224d4254 (diff)
gtestutils: Free test_data when freeing a test case
Commit 9dad94e7q ensured `test_data` is freed when a test is skipped, but didn't ensure that when a whole test suite is skipped. We are assuming the ownership of `test_data` is passed to GTestCase with `g_test_add_data_func_full()` so free `test_data` always when freeing a test case. Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
-rw-r--r--glib/gtestutils.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index 343d6cc96..ab7f1e1bc 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -2996,7 +2996,6 @@ test_case_run (GTestCase *tc,
gchar *old_base = NULL;
GSList **old_free_list, *filename_free_list = NULL;
gboolean success = G_TEST_RUN_SUCCESS;
- gboolean free_test_data = TRUE;
old_base = g_strdup (test_uri_base);
old_free_list = test_filename_free_list;
@@ -3055,7 +3054,7 @@ test_case_run (GTestCase *tc,
}
if (tc->fixture_teardown)
tc->fixture_teardown (fixture, tc->test_data);
- free_test_data = FALSE;
+ tc->fixture_teardown = NULL;
if (tc->fixture_size)
g_free (fixture);
g_timer_stop (test_run_timer);
@@ -3073,13 +3072,6 @@ test_case_run (GTestCase *tc,
g_timer_destroy (test_run_timer);
}
- /* In case the test didn’t run (due to being skipped or an error), the test
- * data may still need to be freed, as the client’s main() function may have
- * passed ownership of it into g_test_add_data_func_full() with a
- * #GDestroyNotify. */
- if (free_test_data && tc->fixture_size == 0 && tc->fixture_teardown != NULL)
- tc->fixture_teardown (tc->test_data, tc->test_data);
-
g_slist_free_full (filename_free_list, g_free);
test_filename_free_list = old_free_list;
g_free (test_uri_base);
@@ -3264,6 +3256,13 @@ g_test_run_suite (GTestSuite *suite)
void
g_test_case_free (GTestCase *test_case)
{
+ /* In case the test didn’t run (due to being skipped or an error), the test
+ * data may still need to be freed, as the client’s main() function may have
+ * passed ownership of it into g_test_add_data_func_full() with a
+ * #GDestroyNotify. */
+ if (test_case->fixture_size == 0 && test_case->fixture_teardown != NULL)
+ test_case->fixture_teardown (test_case->test_data, test_case->test_data);
+
g_free (test_case->name);
g_slice_free (GTestCase, test_case);
}