From 05b226e20e267f1b4368186727e0fbc4b0b43ac6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Wed, 24 Jul 2019 17:22:15 +0200
Subject: [PATCH 22/28] monitor-config-store: Check if a config is system one
before removing it
On meta_monitor_config_store_remove() we save configs if removing a non-system
config, however we were doing the check after the configuration was removed from
the has table, and then potentially destroyed. Causing a memory error.
So, do the check before the removal.
https://gitlab.gnome.org/GNOME/mutter/merge_requests/682
---
src/backends/meta-monitor-config-store.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/backends/meta-monitor-config-store.c b/src/backends/meta-monitor-config-store.c
index e24ce707a..7b0b448ea 100644
--- a/src/backends/meta-monitor-config-store.c
+++ b/src/backends/meta-monitor-config-store.c
@@ -1425,63 +1425,66 @@ maybe_save_configs (MetaMonitorConfigStore *config_store)
/*
* If a custom file is used, it means we are run by the test suite. When this
* is done, avoid replacing the user configuration file with test data,
* except if a custom write file is set as well.
*/
if (!config_store->custom_read_file || config_store->custom_write_file)
meta_monitor_config_store_save (config_store);
}
static gboolean
is_system_config (MetaMonitorsConfig *config)
{
return !!(config->flags & META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG);
}
void
meta_monitor_config_store_add (MetaMonitorConfigStore *config_store,
MetaMonitorsConfig *config)
{
g_hash_table_replace (config_store->configs,
config->key, g_object_ref (config));
if (!is_system_config (config))
maybe_save_configs (config_store);
}
void
meta_monitor_config_store_remove (MetaMonitorConfigStore *config_store,
MetaMonitorsConfig *config)
{
+ gboolean system_config;
+
+ system_config = is_system_config (config);
g_hash_table_remove (config_store->configs, config->key);
- if (!is_system_config (config))
+ if (!system_config)
maybe_save_configs (config_store);
}
gboolean
meta_monitor_config_store_set_custom (MetaMonitorConfigStore *config_store,
const char *read_path,
const char *write_path,
GError **error)
{
g_clear_object (&config_store->custom_read_file);
g_clear_object (&config_store->custom_write_file);
g_hash_table_remove_all (config_store->configs);
config_store->custom_read_file = g_file_new_for_path (read_path);
if (write_path)
config_store->custom_write_file = g_file_new_for_path (write_path);
return read_config_file (config_store,
config_store->custom_read_file,
META_MONITORS_CONFIG_FLAG_NONE,
error);
}
int
meta_monitor_config_store_get_config_count (MetaMonitorConfigStore *config_store)
{
return (int) g_hash_table_size (config_store->configs);
}
MetaMonitorManager *
--
2.26.2