Commit 6cfb23d1 authored by Paolo Borelli's avatar Paolo Borelli

Fix duplicated id detection in gtkbuilder

Fix memory handling of duplicated id hashtable and add unit test
parent bd075575
...@@ -404,7 +404,8 @@ parse_object (GMarkupParseContext *context, ...@@ -404,7 +404,8 @@ parse_object (GMarkupParseContext *context,
return; return;
} }
g_hash_table_insert (data->object_ids, object_id, GINT_TO_POINTER (line));
g_hash_table_insert (data->object_ids, g_strdup (object_id), GINT_TO_POINTER (line));
} }
static void static void
...@@ -1128,7 +1129,8 @@ _gtk_builder_parser_parse_buffer (GtkBuilder *builder, ...@@ -1128,7 +1129,8 @@ _gtk_builder_parser_parse_buffer (GtkBuilder *builder,
data->builder = builder; data->builder = builder;
data->filename = filename; data->filename = filename;
data->domain = g_strdup (domain); data->domain = g_strdup (domain);
data->object_ids = g_hash_table_new (g_str_hash, g_str_equal); data->object_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify)g_free, NULL);
data->requested_objects = NULL; data->requested_objects = NULL;
if (requested_objs) if (requested_objs)
......
...@@ -116,6 +116,13 @@ test_parser (void) ...@@ -116,6 +116,13 @@ test_parser (void)
GTK_BUILDER_ERROR_INVALID_VALUE)); GTK_BUILDER_ERROR_INVALID_VALUE));
g_error_free (error); g_error_free (error);
error = NULL;
gtk_builder_add_from_string (builder, "<interface><object class=\"GtkButton\" id=\"a\"></object><object class=\"GtkButton\" id=\"a\"/></object></interface>", -1, &error);
g_assert (g_error_matches (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_DUPLICATE_ID));
g_error_free (error);
g_object_unref (builder); g_object_unref (builder);
} }
...@@ -2172,7 +2179,7 @@ test_add_objects (void) ...@@ -2172,7 +2179,7 @@ test_add_objects (void)
" </object>" " </object>"
" <object class=\"GtkWindow\" id=\"window2\">" " <object class=\"GtkWindow\" id=\"window2\">"
" <child>" " <child>"
" <object class=\"GtkLabel\" id=\"label1\">" " <object class=\"GtkLabel\" id=\"label3\">"
" <property name=\"label\" translatable=\"no\">second label</property>" " <property name=\"label\" translatable=\"no\">second label</property>"
" </object>" " </object>"
" </child>" " </child>"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment