From 9de0b3df99d1c2fabe03d06c0e9fdec040aafca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 22 Jul 2019 00:05:05 +0200 Subject: [PATCH 19/28] monitor-config-store: Use autopointers to cleanup parse context and buffer https://gitlab.gnome.org/GNOME/mutter/merge_requests/682 --- src/backends/meta-monitor-config-store.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/backends/meta-monitor-config-store.c b/src/backends/meta-monitor-config-store.c index 770bef734..e24ce707a 100644 --- a/src/backends/meta-monitor-config-store.c +++ b/src/backends/meta-monitor-config-store.c @@ -1060,95 +1060,92 @@ handle_text (GMarkupParseContext *context, { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Invalid mode flag %.*s", (int) text_len, text); } return; } case STATE_MONITOR_UNDERSCANNING: { read_bool (text, text_len, &parser->current_monitor_config->enable_underscanning, error); return; } } } static const GMarkupParser config_parser = { .start_element = handle_start_element, .end_element = handle_end_element, .text = handle_text }; static gboolean read_config_file (MetaMonitorConfigStore *config_store, GFile *file, MetaMonitorsConfigFlag extra_config_flags, GError **error) { - char *buffer; + g_autoptr (GMarkupParseContext) parse_context = NULL; + g_autofree char *buffer = NULL; gsize size; ConfigParser parser; - GMarkupParseContext *parse_context; if (!g_file_load_contents (file, NULL, &buffer, &size, NULL, error)) return FALSE; parser = (ConfigParser) { .state = STATE_INITIAL, .config_store = config_store, .extra_config_flags = extra_config_flags, }; parse_context = g_markup_parse_context_new (&config_parser, G_MARKUP_TREAT_CDATA_AS_TEXT | G_MARKUP_PREFIX_ERROR_POSITION, &parser, NULL); if (!g_markup_parse_context_parse (parse_context, buffer, size, error)) { g_list_free_full (parser.current_logical_monitor_configs, (GDestroyNotify) meta_logical_monitor_config_free); g_clear_pointer (&parser.current_monitor_spec, meta_monitor_spec_free); g_free (parser.current_monitor_mode_spec); g_clear_pointer (&parser.current_monitor_config, meta_monitor_config_free); g_clear_pointer (&parser.current_logical_monitor_config, meta_logical_monitor_config_free); return FALSE; } - g_markup_parse_context_free (parse_context); - g_free (buffer); - return TRUE; } MetaMonitorsConfig * meta_monitor_config_store_lookup (MetaMonitorConfigStore *config_store, MetaMonitorsConfigKey *key) { return META_MONITORS_CONFIG (g_hash_table_lookup (config_store->configs, key)); } static void append_monitor_spec (GString *buffer, MetaMonitorSpec *monitor_spec, const char *indentation) { g_string_append_printf (buffer, "%s\n", indentation); g_string_append_printf (buffer, "%s %s\n", indentation, monitor_spec->connector); g_string_append_printf (buffer, "%s %s\n", indentation, monitor_spec->vendor); g_string_append_printf (buffer, "%s %s\n", indentation, monitor_spec->product); g_string_append_printf (buffer, "%s %s\n", indentation, monitor_spec->serial); g_string_append_printf (buffer, "%s\n", indentation); -- 2.26.2