diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index b86244e97..8fdf065a1 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -3639,6 +3639,8 @@ g_test_get_root g_test_suite_add g_test_suite_add_suite g_test_run_suite +g_test_case_free +g_test_suite_free g_test_trap_assertions diff --git a/gio/tests/async-splice-output-stream.c b/gio/tests/async-splice-output-stream.c index fb317b733..3ac03ae67 100644 --- a/gio/tests/async-splice-output-stream.c +++ b/gio/tests/async-splice-output-stream.c @@ -63,6 +63,7 @@ test_copy_chunks_splice_cb (GObject *source, if (data->flags & TEST_CANCEL) { g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED); + g_error_free (error); g_main_loop_quit (data->main_loop); return; } diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 2c3ea24a8..8aafc703b 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -832,6 +832,7 @@ struct DestroyEntry }; /* --- prototypes --- */ +static void test_cleanup (void); static void test_run_seed (const gchar *rseed); static void test_trap_clear (void); static guint8* g_test_log_dump (GTestLogMsg *msg, @@ -1726,6 +1727,18 @@ void test_built_files_dir = test_argv0_dirname; } +static void +test_cleanup (void) +{ + /* Free statically allocated variables */ + + g_clear_pointer (&test_run_rand, g_rand_free); + + g_clear_pointer (&test_argv0_dirname, g_free); + + g_clear_pointer (&test_initial_cwd, g_free); +} + static void test_run_seed (const gchar *rseed) { @@ -2178,8 +2191,15 @@ g_test_get_root (void) int g_test_run (void) { - if (g_test_run_suite (g_test_get_root()) != 0) - return 1; + int ret; + GTestSuite *suite; + + suite = g_test_get_root (); + if (g_test_run_suite (suite) != 0) + { + ret = 1; + goto out; + } /* Clean up the temporary directory. */ if (test_isolate_dirs_tmpdir != NULL) @@ -2192,12 +2212,26 @@ g_test_run (void) /* 77 is special to Automake's default driver, but not Automake's TAP driver * or Perl's prove(1) TAP driver. */ if (test_tap_log) - return 0; + { + ret = 0; + goto out; + } if (test_run_count > 0 && test_run_count == test_skipped_count) - return 77; + { + ret = 77; + goto out; + } else - return 0; + { + ret = 0; + goto out; + } + +out: + g_test_suite_free (suite); + test_cleanup (); + return ret; } /** @@ -2975,6 +3009,41 @@ g_test_run_suite (GTestSuite *suite) return n_bad; } +/** + * g_test_case_free: + * @test_case: a #GTestCase + * + * Free the @test_case. + * + * Since: 2.70 + */ +void +g_test_case_free (GTestCase *test_case) +{ + g_free (test_case->name); + g_slice_free (GTestCase, test_case); +} + +/** + * g_test_suite_free: + * @suite: a #GTestSuite + * + * Free the @suite and all nested #GTestSuites. + * + * Since: 2.70 + */ +void +g_test_suite_free (GTestSuite *suite) +{ + g_slist_free_full (suite->cases, (GDestroyNotify)g_test_case_free); + + g_free (suite->name); + + g_slist_free_full (suite->suites, (GDestroyNotify)g_test_suite_free); + + g_slice_free (GTestSuite, suite); +} + static void gtest_default_log_handler (const gchar *log_domain, GLogLevelFlags log_level, diff --git a/glib/gtestutils.h b/glib/gtestutils.h index 041143936..5be4ce215 100644 --- a/glib/gtestutils.h +++ b/glib/gtestutils.h @@ -506,6 +506,12 @@ void g_test_suite_add_suite (GTestSuite *suite, GLIB_AVAILABLE_IN_ALL int g_test_run_suite (GTestSuite *suite); +GLIB_AVAILABLE_IN_2_70 +void g_test_case_free (GTestCase *test_case); + +GLIB_AVAILABLE_IN_2_70 +void g_test_suite_free (GTestSuite *suite); + GLIB_AVAILABLE_IN_ALL void g_test_trap_assertions (const char *domain, const char *file, diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c index 3d69767e6..8e2e66db5 100644 --- a/glib/gthread-posix.c +++ b/glib/gthread-posix.c @@ -1331,6 +1331,7 @@ g_system_thread_new (GThreadFunc proxy, { g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN, "Error creating thread: %s", g_strerror (ret)); + g_free (thread->thread.name); g_slice_free (GThreadPosix, thread); return NULL; } diff --git a/glib/tests/spawn-path-search.c b/glib/tests/spawn-path-search.c index f4278f3e0..2a8911139 100644 --- a/glib/tests/spawn-path-search.c +++ b/glib/tests/spawn-path-search.c @@ -389,6 +389,8 @@ test_search_path_heap_allocation (void) long_dir = g_test_build_filename (G_TEST_BUILT, "path-test-subdir", placeholder, NULL); long_path = g_strjoin (G_SEARCHPATH_SEPARATOR_S, subdir, long_dir, NULL); envp = g_environ_setenv (envp, "PATH", long_path, TRUE); + g_free (long_path); + g_free (long_dir); g_ptr_array_add (argv, g_test_build_filename (G_TEST_BUILT, "spawn-path-search-helper", NULL)); diff --git a/gobject/tests/param.c b/gobject/tests/param.c index 3ab87ef77..e1f3cdeb1 100644 --- a/gobject/tests/param.c +++ b/gobject/tests/param.c @@ -905,6 +905,7 @@ main (int argc, char *argv[]) data.use_this_flag, data.use_this_type); test_data = g_memdup2 (&data, sizeof (TestParamImplementData)); g_test_add_data_func_full (test_path, test_data, test_param_implement_child, g_free); + g_free (test_data); g_free (test_path); }