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:
parent
5ed954e6de
commit
7a1393ba26
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user