[glib: 2/5] tests: Free GSettingsBackend singleton at end of gsettings tests




commit 98274e09de4b785fe69d5f1f5d9a444583a760e2
Author: Philip Withnall <withnall endlessm com>
Date:   Wed Jan 23 16:26:09 2019 +0000

    tests: Free GSettingsBackend singleton at end of gsettings tests
    
    This makes the tests a whole lot closer to being valgrind-clean, and
    revealed a few legitimate memory leaks in amongst the noise caused by
    keeping the singleton GSettingsBackend around for the lifetime of the
    process.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 gio/tests/gsettings.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
---
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
index 179d0fd2f..16eb228c4 100644
--- a/gio/tests/gsettings.c
+++ b/gio/tests/gsettings.c
@@ -3001,5 +3001,19 @@ main (int argc, char *argv[])
 
   g_settings_sync ();
 
+  /* FIXME: Due to the way #GSettings objects can be used without specifying a
+   * backend, the default backend is leaked. In order to be able to run this
+   * test under valgrind and get meaningful checking for real leaks, use this
+   * hack to drop the final reference to the default #GSettingsBackend.
+   *
+   * This should not be used in production code. */
+    {
+      GSettingsBackend *backend;
+
+      backend = g_settings_backend_get_default ();
+      g_object_unref (backend);  /* reference from the *_get_default() call */
+      g_assert_finalize_object (backend);  /* singleton reference owned by GLib */
+    }
+
   return result;
 }


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