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
This commit is contained in:
Jonas Ådahl 2017-09-11 11:24:37 +08:00
parent 5ed954e6de
commit 7a1393ba26

View File

@ -1248,37 +1248,20 @@ saved_cb (GObject *object,
}
static void
meta_monitor_config_store_save (MetaMonitorConfigStore *config_store)
meta_monitor_config_store_save_sync (MetaMonitorConfigStore *config_store)
{
GError *error = NULL;
GFile *file;
GString *buffer;
SaveData *data;
if (config_store->save_cancellable)
{
g_cancellable_cancel (config_store->save_cancellable);
g_clear_object (&config_store->save_cancellable);
}
config_store->save_cancellable = g_cancellable_new ();
if (config_store->custom_write_file)
file = config_store->custom_write_file;
else
file = config_store->user_file;
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
* 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,
if (!g_file_replace_contents (file,
buffer->str, buffer->len,
NULL,
FALSE,
@ -1291,9 +1274,43 @@ meta_monitor_config_store_save (MetaMonitorConfigStore *config_store)
error->message);
g_error_free (error);
}
g_string_free (buffer, TRUE);
}
static void
meta_monitor_config_store_save (MetaMonitorConfigStore *config_store)
{
GString *buffer;
SaveData *data;
if (config_store->save_cancellable)
{
g_cancellable_cancel (config_store->save_cancellable);
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);
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,