[gnome-software/gnome-3-22] Fix weirdness when de-duplicating applications



commit f1e6192c2595ddf0570f5bccbe3038f6e7b69f8f
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 ba09484..7228f4c 100644
--- a/src/gs-app-list.c
+++ b/src/gs-app-list.c
@@ -120,7 +120,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));
 }
 
 /**
@@ -451,8 +451,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);
-       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);
 }
 
 /**


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