Blame SOURCES/0022-monitor-config-store-Check-if-a-config-is-system-one.patch

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