[gnome-software] plugin loader: Create a deep copy when returning pending apps array



commit c9ead174540a5463ed7199bd46762ed7c1edb6db
Author: Kalev Lember <kalevlember gmail com>
Date:   Wed Mar 11 23:08:14 2015 +0100

    plugin loader: Create a deep copy when returning pending apps array
    
    Otherwise if we return a pointer to the internal array, a plugin worker
    thread can modify the array while we're accessing it.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1200944

 src/gs-plugin-loader.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 2118f15..6488d62 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -2782,7 +2782,20 @@ gs_plugin_loader_get_state_for_app (GsPluginLoader *plugin_loader, GsApp *app)
 GPtrArray *
 gs_plugin_loader_get_pending (GsPluginLoader *plugin_loader)
 {
-       return g_ptr_array_ref (plugin_loader->priv->pending_apps);
+       GsPluginLoaderPrivate *priv = plugin_loader->priv;
+       GPtrArray *array;
+       guint i;
+
+       array = g_ptr_array_new_with_free_func ((GFreeFunc) g_object_unref);
+
+       g_mutex_lock (&priv->pending_apps_mutex);
+       for (i = 0; i < priv->pending_apps->len; i++) {
+               GsApp *app = g_ptr_array_index (priv->pending_apps, i);
+               g_ptr_array_add (array, g_object_ref (app));
+       }
+       g_mutex_unlock (&plugin_loader->priv->pending_apps_mutex);
+
+       return array;
 }
 
 /**


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