[gnome-software/wip/kalev/gnome-3-22-prep: 14/52] Fix weirdness when de-duplicating applications



commit e4995c45cc1f476196d250ea115277417fb32d1e
Author: Richard Hughes <richard hughsie com>
Date:   Tue Sep 20 14:29:42 2016 +0100

    Fix weirdness when de-duplicating applications
    
    This took some time to find. When we were adding the unique_id to the hash
    table we were not duplicating the unique ID. If we then added some information
    (for example, the branch in refine) the unique ID would be marked as invalidated
    which meant that it was automatically re-generated whenever it was needed again.
    
    In the meantime, when we got hash table GHashFunc matches we would run the
    GEqualFunc on the now-free'd memory area and fail to see that the keys were
    indeed equal.
    
    (cherry picked from commit 6b53a8ab525ec5e46712a67248f9bbba22851a35)

 src/gs-app-list.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-app-list.c b/src/gs-app-list.c
index 29ebe87..509f58a 100644
--- a/src/gs-app-list.c
+++ b/src/gs-app-list.c
@@ -134,7 +134,7 @@ gs_app_list_add_safe (GsAppList *list, GsApp *app)
 
        /* just use the ref */
        g_ptr_array_add (list->array, g_object_ref (app));
-       g_hash_table_insert (list->hash_by_id, (gpointer) id, (gpointer) app);
+       g_hash_table_insert (list->hash_by_id, g_strdup (id), g_object_ref (app));
 }
 
 /**
@@ -466,8 +466,10 @@ gs_app_list_init (GsAppList *list)
        g_mutex_init (&list->mutex);
        list->array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
 #if AS_CHECK_VERSION(0,6,2)
-       list->hash_by_id = g_hash_table_new ((GHashFunc) as_utils_unique_id_hash,
-                                            (GEqualFunc) as_utils_unique_id_equal);
+       list->hash_by_id = g_hash_table_new_full ((GHashFunc) as_utils_unique_id_hash,
+                                                 (GEqualFunc) as_utils_unique_id_equal,
+                                                 g_free,
+                                                 (GDestroyNotify) g_object_unref);
 #else
        list->hash_by_id = g_hash_table_new (g_str_hash, g_str_equal);
 #endif


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