Merge branch 'free' into 'main'

gtestutils: Free test_data when freeing a test case

See merge request GNOME/glib!4120
This commit is contained in:
Philip Withnall 2024-06-26 12:45:05 +00:00
commit e2a36f8b05

View File

@ -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 didnt run (due to being skipped or an error), the test
* data may still need to be freed, as the clients 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 didnt run (due to being skipped or an error), the test
* data may still need to be freed, as the clients 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);
}