[gnome-software/gnome-3-30] plugin loader: Make gs_plugin_loader_get_event_default thread safe



commit 6ed8412f0deee016af2b8b43d94ba679c6858031
Author: Kalev Lember <klember redhat com>
Date:   Fri Nov 30 16:39:37 2018 +0100

    plugin loader: Make gs_plugin_loader_get_event_default thread safe
    
    We have to take a ref on the event while holding the lock, as otherwise
    a plugin worker thread might destroy it (by adding a new event with the
    same unique ID to the hash table) while we're processing it in the main
    thread.

 lib/gs-plugin-loader.c       | 4 ++--
 plugins/dummy/gs-self-test.c | 2 +-
 src/gs-shell.c               | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index b811d66d..be3078d4 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1996,7 +1996,7 @@ gs_plugin_loader_get_events (GsPluginLoader *plugin_loader)
  * Gets an active plugin event where active means that it was not been
  * already dismissed by the user.
  *
- * Returns: a #GsPluginEvent, or %NULL for none
+ * Returns: (transfer full): a #GsPluginEvent, or %NULL for none
  **/
 GsPluginEvent *
 gs_plugin_loader_get_event_default (GsPluginLoader *plugin_loader)
@@ -2015,7 +2015,7 @@ gs_plugin_loader_get_event_default (GsPluginLoader *plugin_loader)
                        continue;
                }
                if (!gs_plugin_event_has_flag (event, GS_PLUGIN_EVENT_FLAG_INVALID))
-                       return event;
+                       return g_object_ref (event);
        }
        return NULL;
 }
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index fb90f8f4..cac89697 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -95,12 +95,12 @@ gs_plugins_dummy_install_func (GsPluginLoader *plugin_loader)
 static void
 gs_plugins_dummy_error_func (GsPluginLoader *plugin_loader)
 {
-       GsPluginEvent *event;
        const GError *app_error;
        gboolean ret;
        g_autoptr(GError) error = NULL;
        g_autoptr(GPtrArray) events = NULL;
        g_autoptr(GsApp) app = NULL;
+       g_autoptr(GsPluginEvent) event = NULL;
        g_autoptr(GsPluginJob) plugin_job = NULL;
 
        /* drop all caches */
diff --git a/src/gs-shell.c b/src/gs-shell.c
index b6afa83e..6f1cda81 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -1909,9 +1909,9 @@ gs_shell_show_event (GsShell *shell, GsPluginEvent *event)
 static void
 gs_shell_rescan_events (GsShell *shell)
 {
-       GsPluginEvent *event;
        GsShellPrivate *priv = gs_shell_get_instance_private (shell);
        GtkWidget *widget;
+       g_autoptr(GsPluginEvent) event = NULL;
 
        /* find the first active event and show it */
        event = gs_plugin_loader_get_event_default (priv->plugin_loader);


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