[gnome-online-accounts/gnome-3-12] identity: Keep a reference to self during async operations



commit a0d4e367531576c2d188692f25dca4bdcc3d3c4e
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Apr 9 15:31:50 2014 +0200

    identity: Keep a reference to self during async operations
    
    If the IdentityService object is freed while it's getting the initial
    list of identities shortly after start up (i.e., the service is
    exiting shortly after starting), then there's a chance the callback
    associated with the identity listing operation could be called after
    the service is freed (which could lead to a crash).
    
    This commit addresses that problem by reffing the service object until
    the list operation finishes, preventing it from getting freed
    prematurely.
    
    Fixes: https://bugzilla.gnome.org/727896

 src/goaidentity/goaidentityservice.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/src/goaidentity/goaidentityservice.c b/src/goaidentity/goaidentityservice.c
index ef279c3..499c783 100644
--- a/src/goaidentity/goaidentityservice.c
+++ b/src/goaidentity/goaidentityservice.c
@@ -1596,7 +1596,7 @@ on_identities_listed (GoaIdentityManager *manager,
           g_warning ("Could not list identities: %s", error->message);
           g_error_free (error);
         }
-      return;
+      goto out;
     }
 
   for (node = identities; node != NULL; node = node->next)
@@ -1616,6 +1616,9 @@ on_identities_listed (GoaIdentityManager *manager,
       else
         g_object_unref (object);
     }
+
+ out:
+  g_object_unref (self);
 }
 
 static void
@@ -1678,7 +1681,7 @@ on_got_client (GoaClient          *client,
   if (self->priv->client == NULL)
     {
       g_warning ("Could not create client: %s", error->message);
-      return;
+      goto out;
     }
 
   self->priv->accounts_manager = goa_client_get_manager (client);
@@ -1688,16 +1691,19 @@ on_got_client (GoaClient          *client,
   if (self->priv->identity_manager == NULL)
     {
       g_warning ("Could not create identity manager: %s", error->message);
-      return;
+      goto out;
     }
 
   goa_identity_manager_list_identities (self->priv->identity_manager,
                                         NULL,
                                         (GAsyncReadyCallback)
                                         on_identities_listed,
-                                        self);
+                                        g_object_ref (self));
 
   ensure_credentials_for_accounts (self);
+
+ out:
+  g_object_unref (self);
 }
 
 static void
@@ -1717,7 +1723,7 @@ on_session_bus_acquired (GDBusConnection    *connection,
     goa_client_new (NULL,
                     (GAsyncReadyCallback)
                     on_got_client,
-                    self);
+                    g_object_ref (self));
   }
 }
 


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