From 7a1393ba2626f468e4a8a303d6705caf9a8b86e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 11 Sep 2017 11:24:37 +0800 Subject: [PATCH] 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 file changed, 42 insertions(+), 25 deletions(-) diff --git a/src/backends/meta-monitor-config-store.c b/src/backends/meta-monitor-config-store.c index 95192c913..a33ef752d 100644 --- a/src/backends/meta-monitor-config-store.c +++ b/src/backends/meta-monitor-config-store.c @@ -1247,6 +1247,37 @@ saved_cb (GObject *object, g_free (data); } +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) { @@ -1259,6 +1290,17 @@ meta_monitor_config_store_save (MetaMonitorConfigStore *config_store) g_clear_object (&config_store->save_cancellable); } + /* + * 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 + * custom write files, do the content replacement synchronously. + */ + if (config_store->custom_write_file) + { + meta_monitor_config_store_save_sync (config_store); + return; + } + config_store->save_cancellable = g_cancellable_new (); buffer = generate_config_xml (config_store); @@ -1269,31 +1311,6 @@ meta_monitor_config_store_save (MetaMonitorConfigStore *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 - * custom write files, do the content replacement synchronously. - */ - 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); - } - return; - } - g_file_replace_contents_async (config_store->user_file, buffer->str, buffer->len, NULL,