Blame SOURCES/0019-monitor-config-store-Use-autopointers-to-cleanup-par.patch

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