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



commit 4d81406a9559885bc30b70ccf819ab8f359828a1
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 4c79600..d2ce877 100644
--- a/src/goaidentity/goaidentityservice.c
+++ b/src/goaidentity/goaidentityservice.c
@@ -1593,7 +1593,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)
@@ -1613,6 +1613,9 @@ on_identities_listed (GoaIdentityManager *manager,
       else
         g_object_unref (object);
     }
+
+ out:
+  g_object_unref (self);
 }
 
 static void
@@ -1675,7 +1678,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);
@@ -1685,16 +1688,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
@@ -1714,7 +1720,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]