[gnome-desktop/gnome-3-8] gnome-xkb-info: Don't store duplicated layouts in locale tables



commit 886a568ea6b53772674cdcda1a770a0093eaf9fb
Author: Rui Matos <tiagomatos gmail com>
Date:   Thu Mar 7 11:34:28 2013 +0100

    gnome-xkb-info: Don't store duplicated layouts in locale tables
    
    We can't store duplicated layouts anywhere since those get destroyed
    when the 'layout' element ends and we'd end up with invalid entries
    potentially leading to crashes when used.
    
    Just doing a g_hash_table_remove() on the layouts_by_* tables was a
    thinko and could never work since those only contain other tables as
    values and it's in this second level tables that the layouts are
    stored.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695350

 libgnome-desktop/gnome-xkb-info.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/libgnome-desktop/gnome-xkb-info.c b/libgnome-desktop/gnome-xkb-info.c
index cc43f91..7e2df28 100644
--- a/libgnome-desktop/gnome-xkb-info.c
+++ b/libgnome-desktop/gnome-xkb-info.c
@@ -367,13 +367,21 @@ add_layout_to_table (GHashTable  *table,
 {
   GHashTable *set;
 
+  if (!layout->xkb_name)
+    return;
+
   set = g_hash_table_lookup (table, key);
   if (!set)
     {
-      set = g_hash_table_new (NULL, NULL);
+      set = g_hash_table_new (g_str_hash, g_str_equal);
       g_hash_table_replace (table, g_strdup (key), set);
     }
-  g_hash_table_add (set, layout);
+  else
+    {
+      if (g_hash_table_contains (set, layout->xkb_name))
+        return;
+    }
+  g_hash_table_replace (set, layout->xkb_name, layout);
 }
 
 static void
@@ -397,8 +405,6 @@ parse_end_element (GMarkupParseContext  *context,
 
       if (g_hash_table_contains (priv->layouts_table, priv->current_parser_layout->id))
         {
-          g_hash_table_remove (priv->layouts_by_country, priv->current_parser_layout);
-          g_hash_table_remove (priv->layouts_by_language, priv->current_parser_layout);
           g_clear_pointer (&priv->current_parser_layout, free_layout);
           return;
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]