[glib: 4/9] glib/gtestutils: Introduce and use a test_cleanup function




commit bd779c96e946402851e42505ed36e984b303d3e9
Author: GOUJON Évan <goujon evan gmail com>
Date:   Fri Jul 23 22:20:54 2021 +0200

    glib/gtestutils: Introduce and use a test_cleanup function

 glib/gtestutils.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
---
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index ab80e48b2..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)
 {
@@ -2217,6 +2230,7 @@ g_test_run (void)
 
 out:
   g_test_suite_free (suite);
+  test_cleanup ();
   return ret;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]