[gnome-software] Never reuse a GCancellable to prevent a crash



commit 677f8dc650840cbd28a3c4b0460dacdbd01f8217
Author: Richard Hughes <richard hughsie com>
Date:   Sat Aug 9 09:32:03 2014 +0200

    Never reuse a GCancellable to prevent a crash
    
    It turns out we need to create a GCancellable for each async task, passing it
    down to any async tasks in the chain.

 src/gs-shell-search-provider.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/src/gs-shell-search-provider.c b/src/gs-shell-search-provider.c
index 1827b30..5597e5a 100644
--- a/src/gs-shell-search-provider.c
+++ b/src/gs-shell-search-provider.c
@@ -36,6 +36,7 @@ typedef struct {
        GsShellSearchProvider *provider;
        GDBusMethodInvocation *invocation;
        gint ref_count;
+       GCancellable *cancellable;
 } PendingSearch;
 
 struct _GsShellSearchProvider {
@@ -45,7 +46,6 @@ struct _GsShellSearchProvider {
        GDBusObjectManagerServer *object_manager;
        GsShellSearchProvider2 *skeleton;
        GsPluginLoader *plugin_loader;
-       GCancellable *cancellable;
        PendingSearch *current_search;
 
        GHashTable *metas_cache;
@@ -66,8 +66,10 @@ pending_search_unref (PendingSearch *search)
 {
        search->ref_count--;
 
-       if (search->ref_count == 0)
+       if (search->ref_count == 0) {
+               g_object_unref (search->cancellable);
                g_slice_free (PendingSearch, search);
+       }
 }
 
 static void
@@ -76,8 +78,7 @@ cancel_current_search (GsShellSearchProvider *self)
        if (self->current_search) {
                PendingSearch *search;
 
-               g_cancellable_cancel (self->cancellable);
-               g_cancellable_reset (self->cancellable);
+               g_cancellable_cancel (self->current_search->cancellable);
 
                search = self->current_search;
                self->current_search = NULL;
@@ -170,9 +171,10 @@ execute_search (GsShellSearchProvider  *self,
        self->current_search->provider = self;
        self->current_search->invocation = invocation;
        self->current_search->ref_count = 1;
+       self->current_search->cancellable = g_cancellable_new ();
 
        gs_plugin_loader_search_async (self->plugin_loader,
-                                      string, 0, self->cancellable,
+                                      string, 0, self->current_search->cancellable,
                                       search_done_cb,
                                       pending_search_ref (self->current_search));
        g_free (string);
@@ -367,7 +369,6 @@ search_provider_dispose (GObject *obj)
 
        g_clear_object (&self->object_manager);
        g_clear_object (&self->plugin_loader);
-       g_clear_object (&self->cancellable);
        g_hash_table_destroy (self->metas_cache);
        cancel_current_search (self);
        g_application_release (g_application_get_default ());
@@ -410,5 +411,4 @@ gs_shell_search_provider_setup (GsShellSearchProvider *provider,
                                GsPluginLoader *loader)
 {
        provider->plugin_loader = g_object_ref (loader);
-       provider->cancellable = g_cancellable_new ();
 }


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