[gnome-software/gnome-3-26] Add missing locking for Fedora distro upgrades plugin



commit aef4ebb0d29a8d6d145fb08b7bd79d3e1691406d
Author: Kalev Lember <klember redhat com>
Date:   Tue Oct 31 17:34:16 2017 +0100

    Add missing locking for Fedora distro upgrades plugin
    
    This should fix multiple crashers reported in Fedora bugzilla for 3.26
    that all look like they are due to accessing internal data structures
    (mainly priv->distros) concurrently from multiple threads.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1502816
    https://bugzilla.redhat.com/show_bug.cgi?id=1507307

 .../gs-plugin-fedora-pkgdb-collections.c           |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c 
b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
index 46aeefa..ca60313 100644
--- a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
+++ b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
@@ -37,6 +37,7 @@ struct GsPluginData {
        GSettings       *settings;
        gboolean         is_valid;
        GPtrArray       *distros;
+       GMutex           mutex;
 };
 
 typedef enum {
@@ -64,6 +65,8 @@ gs_plugin_initialize (GsPlugin *plugin)
 {
        GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
 
+       g_mutex_init (&priv->mutex);
+
        /* check that we are running on Fedora */
        if (!gs_plugin_check_distro_id (plugin, "fedora")) {
                gs_plugin_set_enabled (plugin, FALSE);
@@ -94,6 +97,7 @@ gs_plugin_destroy (GsPlugin *plugin)
                g_ptr_array_unref (priv->distros);
        g_free (priv->os_name);
        g_free (priv->cachefn);
+       g_mutex_clear (&priv->mutex);
 }
 
 static void
@@ -129,6 +133,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
        gchar *endptr = NULL;
        g_autoptr(GFile) file = NULL;
        g_autoptr(GsOsRelease) os_release = NULL;
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
 
        /* get the file to cache */
        priv->cachefn = gs_utils_get_cache_filename ("upgrades",
@@ -231,6 +236,9 @@ gs_plugin_refresh (GsPlugin *plugin,
                   GCancellable *cancellable,
                   GError **error)
 {
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
+
        /* only for update metadata */
        if ((flags & GS_PLUGIN_REFRESH_FLAGS_METADATA) == 0)
                return TRUE;
@@ -500,6 +508,7 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
                               GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
 
        /* ensure valid data is loaded */
        if (!_ensure_cache (plugin, cancellable, error))
@@ -525,8 +534,10 @@ gs_plugin_refine_app (GsPlugin *plugin,
                      GCancellable *cancellable,
                      GError **error)
 {
+       GsPluginData *priv = gs_plugin_get_data (plugin);
        PkgdbItem *item;
        const gchar *cpe_name;
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->mutex);
 
        /* not for us */
        if (gs_app_get_kind (app) != AS_APP_KIND_OS_UPGRADE)


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