[mutter] monitor-config-store: Don't leak when saving synchronously



commit 7a1393ba2626f468e4a8a303d6705caf9a8b86e2
Author: Jonas Ådahl <jadahl gmail com>
Date:   Mon Sep 11 11:24:37 2017 +0800

    monitor-config-store: Don't leak when saving synchronously
    
    We currently only save synchronously when running the test suite, but
    should still not leak the generated config buffer. We also created the
    cancellable but never used it if we saved synchronously, so lets stop
    doing that too.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=787477

 src/backends/meta-monitor-config-store.c |   67 +++++++++++++++++++-----------
 1 files changed, 42 insertions(+), 25 deletions(-)
---
diff --git a/src/backends/meta-monitor-config-store.c b/src/backends/meta-monitor-config-store.c
index 95192c9..a33ef75 100644
--- a/src/backends/meta-monitor-config-store.c
+++ b/src/backends/meta-monitor-config-store.c
@@ -1248,6 +1248,37 @@ saved_cb (GObject      *object,
 }
 
 static void
+meta_monitor_config_store_save_sync (MetaMonitorConfigStore *config_store)
+{
+  GError *error = NULL;
+  GFile *file;
+  GString *buffer;
+
+  if (config_store->custom_write_file)
+    file = config_store->custom_write_file;
+  else
+    file = config_store->user_file;
+
+  buffer = generate_config_xml (config_store);
+
+  if (!g_file_replace_contents (file,
+                                buffer->str, buffer->len,
+                                NULL,
+                                FALSE,
+                                G_FILE_CREATE_REPLACE_DESTINATION,
+                                NULL,
+                                NULL,
+                                &error))
+    {
+      g_warning ("Saving monitor configuration failed: %s\n",
+                 error->message);
+      g_error_free (error);
+    }
+
+  g_string_free (buffer, TRUE);
+}
+
+static void
 meta_monitor_config_store_save (MetaMonitorConfigStore *config_store)
 {
   GString *buffer;
@@ -1259,16 +1290,6 @@ meta_monitor_config_store_save (MetaMonitorConfigStore *config_store)
       g_clear_object (&config_store->save_cancellable);
     }
 
-  config_store->save_cancellable = g_cancellable_new ();
-
-  buffer = generate_config_xml (config_store);
-
-  data = g_new0 (SaveData, 1);
-  *data = (SaveData) {
-    .config_store = g_object_ref (config_store),
-    .buffer = buffer
-  };
-
   /*
    * Custom write file is only ever used by the test suite, and the test suite
    * will want to have be able to read back the content immediately, so for
@@ -1276,24 +1297,20 @@ meta_monitor_config_store_save (MetaMonitorConfigStore *config_store)
    */
   if (config_store->custom_write_file)
     {
-      GError *error = NULL;
-
-      if (!g_file_replace_contents (config_store->custom_write_file,
-                                    buffer->str, buffer->len,
-                                    NULL,
-                                    FALSE,
-                                    G_FILE_CREATE_REPLACE_DESTINATION,
-                                    NULL,
-                                    NULL,
-                                    &error))
-        {
-          g_warning ("Saving monitor configuration failed: %s\n",
-                     error->message);
-          g_error_free (error);
-        }
+      meta_monitor_config_store_save_sync (config_store);
       return;
     }
 
+  config_store->save_cancellable = g_cancellable_new ();
+
+  buffer = generate_config_xml (config_store);
+
+  data = g_new0 (SaveData, 1);
+  *data = (SaveData) {
+    .config_store = g_object_ref (config_store),
+    .buffer = buffer
+  };
+
   g_file_replace_contents_async (config_store->user_file,
                                  buffer->str, buffer->len,
                                  NULL,


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