gsettings: fix schema compiler error handling
authorRyan Lortie <desrt@desrt.ca>
Thu, 9 Apr 2015 02:08:13 +0000 (22:08 -0400)
committerRyan Lortie <desrt@desrt.ca>
Thu, 9 Apr 2015 02:35:35 +0000 (22:35 -0400)
Fix a couple of issues in error handling in glib-compile-schemas.

The first problem is that, in case of repeated <summary> or
<description> tags we were still allocating a GString which was never
being freed (due to the throwing of the error resulting in immediate
termination of the parse).

The second problem is that if the repeated <summary> tag also had
attributes, we would attempt to set the GError twice.

https://bugzilla.gnome.org/show_bug.cgi?id=747542

gio/glib-compile-schemas.c

index a09ceae..2b3e0de 100644 (file)
@@ -1383,27 +1383,33 @@ start_element (GMarkupParseContext  *context,
 
       else if (strcmp (element_name, "summary") == 0)
         {
-          if (state->key_state->summary_seen && state->strict)
-            g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
-                         _("Only one <%s> element allowed inside <%s>"),
-                         element_name, container);
-          state->key_state->summary_seen = TRUE;
-
           if (NO_ATTRS ())
-            state->string = g_string_new (NULL);
+            {
+              if (state->key_state->summary_seen && state->strict)
+                g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
+                             _("Only one <%s> element allowed inside <%s>"),
+                             element_name, container);
+              else
+                state->string = g_string_new (NULL);
+
+              state->key_state->summary_seen = TRUE;
+            }
           return;
         }
 
       else if (strcmp (element_name, "description") == 0)
         {
-          if (state->key_state->description_seen && state->strict)
-            g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
-                         _("Only one <%s> element allowed inside <%s>"),
-                         element_name, container);
-          state->key_state->description_seen = TRUE;
-
           if (NO_ATTRS ())
-            state->string = g_string_new (NULL);
+            {
+              if (state->key_state->description_seen && state->strict)
+                g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
+                             _("Only one <%s> element allowed inside <%s>"),
+                             element_name, container);
+              else
+                state->string = g_string_new (NULL);
+
+            state->key_state->description_seen = TRUE;
+            }
           return;
         }