Merge branch 'source-static-name' into 'main'

Port internal uses to use g_source_set_static_name()

See merge request GNOME/glib!2198
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index b86244e..8fdf065 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -3639,6 +3639,8 @@
 g_test_suite_add
 g_test_suite_add_suite
 g_test_run_suite
+g_test_case_free
+g_test_suite_free
 
 <SUBSECTION Private>
 g_test_trap_assertions
diff --git a/gio/tests/async-splice-output-stream.c b/gio/tests/async-splice-output-stream.c
index fb317b7..3ac03ae 100644
--- a/gio/tests/async-splice-output-stream.c
+++ b/gio/tests/async-splice-output-stream.c
@@ -63,6 +63,7 @@
   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 2c3ea24..8aafc70 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -832,6 +832,7 @@
 };
 
 /* --- 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,
@@ -1727,6 +1728,18 @@
 }
 
 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)
 {
   guint seed_failed = 0;
@@ -2178,8 +2191,15 @@
 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 @@
   /* 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 @@
   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 0411439..5be4ce2 100644
--- a/glib/gtestutils.h
+++ b/glib/gtestutils.h
@@ -506,6 +506,12 @@
 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 3d69767..8e2e66d 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -1331,6 +1331,7 @@
     {
       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 f4278f3..2a89111 100644
--- a/glib/tests/spawn-path-search.c
+++ b/glib/tests/spawn-path-search.c
@@ -389,6 +389,8 @@
   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 3ab87ef..e1f3cde 100644
--- a/gobject/tests/param.c
+++ b/gobject/tests/param.c
@@ -905,6 +905,7 @@
                                          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);
           }