[gnome-software/gnome-3-30] flatpak: Add missing locking around broken_remotes hash table



commit 4d90756e20b8fec60a5175b59582ff926ebc4c36
Author: Kalev Lember <klember redhat com>
Date:   Thu Dec 27 14:35:21 2018 +0100

    flatpak: Add missing locking around broken_remotes hash table
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1641314

 plugins/flatpak/gs-flatpak.c | 8 ++++++++
 1 file changed, 8 insertions(+)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index b835d843..ad94e507 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -41,6 +41,7 @@ struct _GsFlatpak {
        GsFlatpakFlags           flags;
        FlatpakInstallation     *installation;
        GHashTable              *broken_remotes;
+       GMutex                   broken_remotes_mutex;
        GFileMonitor            *monitor;
        AsAppScope               scope;
        GsPlugin                *plugin;
@@ -667,11 +668,14 @@ gs_flatpak_refresh_appstream (GsFlatpak *self, guint cache_age,
                g_autoptr(GFile) file_timestamp = NULL;
                g_autofree gchar *appstream_fn = NULL;
                FlatpakRemote *xremote = g_ptr_array_index (xremotes, i);
+               g_autoptr(GMutexLocker) locker = NULL;
 
                /* not enabled */
                if (flatpak_remote_get_disabled (xremote))
                        continue;
 
+               locker = g_mutex_locker_new (&self->broken_remotes_mutex);
+
                /* skip known-broken repos */
                remote_name = flatpak_remote_get_name (xremote);
                if (g_hash_table_lookup (self->broken_remotes, remote_name) != NULL) {
@@ -1268,7 +1272,9 @@ gs_flatpak_refresh (GsFlatpak *self,
                    GError **error)
 {
        /* give all the repos a second chance */
+       g_mutex_lock (&self->broken_remotes_mutex);
        g_hash_table_remove_all (self->broken_remotes);
+       g_mutex_unlock (&self->broken_remotes_mutex);
 
        /* manually drop the cache */
        if (!flatpak_installation_drop_caches (self->installation,
@@ -2574,6 +2580,7 @@ gs_flatpak_finalize (GObject *object)
        g_object_unref (self->plugin);
        g_object_unref (self->store);
        g_hash_table_unref (self->broken_remotes);
+       g_mutex_clear (&self->broken_remotes_mutex);
 
        G_OBJECT_CLASS (gs_flatpak_parent_class)->finalize (object);
 }
@@ -2588,6 +2595,7 @@ gs_flatpak_class_init (GsFlatpakClass *klass)
 static void
 gs_flatpak_init (GsFlatpak *self)
 {
+       g_mutex_init (&self->broken_remotes_mutex);
        self->broken_remotes = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                      g_free, NULL);
        self->store = as_store_new ();


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