From d585e6d6f15122ca58995603cfc67bfeb111b0d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 25 Jul 2019 01:24:01 +0200 Subject: [PATCH 23/28] monitor-config-migration: Unref the new config once added to the store When migrating the configurations we've a leak because the config is passed to the store that takes its ownership via meta_monitor_config_store_add(), but we never relase the reference of the newly created object. So use an auto-pointer to manage the object lifetime when returning. https://gitlab.gnome.org/GNOME/mutter/merge_requests/682 --- src/backends/meta-monitor-config-migration.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backends/meta-monitor-config-migration.c b/src/backends/meta-monitor-config-migration.c index d619dc433..ed6c80184 100644 --- a/src/backends/meta-monitor-config-migration.c +++ b/src/backends/meta-monitor-config-migration.c @@ -1067,94 +1067,93 @@ find_disabled_monitor_specs (MetaLegacyMonitorsConfig *legacy_config) MetaOutputKey *output_key = &legacy_config->keys[i]; MetaOutputConfig *output_config = &legacy_config->outputs[i]; MetaMonitorSpec *monitor_spec; if (output_config->enabled) continue; monitor_spec = g_new0 (MetaMonitorSpec, 1); *monitor_spec = (MetaMonitorSpec) { .connector = output_key->connector, .vendor = output_key->vendor, .product = output_key->product, .serial = output_key->serial }; disabled_monitors = g_list_prepend (disabled_monitors, monitor_spec); } return disabled_monitors; } static void migrate_config (gpointer key, gpointer value, gpointer user_data) { MetaLegacyMonitorsConfig *legacy_config = key; MetaMonitorConfigStore *config_store = user_data; MetaMonitorManager *monitor_manager = meta_monitor_config_store_get_monitor_manager (config_store); + g_autoptr (MetaMonitorsConfig) config = NULL; GList *logical_monitor_configs; MetaLogicalMonitorLayoutMode layout_mode; GError *error = NULL; GList *disabled_monitor_specs; - MetaMonitorsConfig *config; logical_monitor_configs = derive_logical_monitor_configs (legacy_config, config_store, &error); if (!logical_monitor_configs) { g_autofree char *config_name = NULL; config_name = generate_config_name (legacy_config); g_warning ("Failed to migrate monitor configuration for %s: %s", config_name, error->message); return; } disabled_monitor_specs = find_disabled_monitor_specs (legacy_config); layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL; config = meta_monitors_config_new_full (logical_monitor_configs, disabled_monitor_specs, layout_mode, META_MONITORS_CONFIG_FLAG_MIGRATED); if (!meta_verify_monitors_config (config, monitor_manager, &error)) { g_autofree char *config_name = NULL; config_name = generate_config_name (legacy_config); g_warning ("Ignoring invalid monitor configuration for %s: %s", config_name, error->message); - g_object_unref (config); return; } meta_monitor_config_store_add (config_store, config); } gboolean meta_migrate_old_monitors_config (MetaMonitorConfigStore *config_store, GFile *in_file, GError **error) { g_autoptr (GHashTable) configs = NULL; configs = load_config_file (in_file, error); if (!configs) return FALSE; g_hash_table_foreach (configs, migrate_config, config_store); return TRUE; } gboolean meta_migrate_old_user_monitors_config (MetaMonitorConfigStore *config_store, GError **error) { g_autofree char *backup_path = NULL; g_autoptr (GFile) backup_file = NULL; g_autofree char *user_file_path = NULL; g_autoptr (GFile) user_file = NULL; -- 2.26.2