[gnome-online-accounts/rhel-7.1: 13/34] identity: Keep a reference to self during async operations



commit a7a34870a716c8860c9ef60ea332baee6c7de07b
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 |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/src/goaidentity/goaidentityservice.c b/src/goaidentity/goaidentityservice.c
index 3321b0f..d51d6bd 100644
--- a/src/goaidentity/goaidentityservice.c
+++ b/src/goaidentity/goaidentityservice.c
@@ -1598,7 +1598,7 @@ on_identities_listed (GoaIdentityManager *manager,
           goa_warning ("Could not list identities: %s", error->message);
           g_error_free (error);
         }
-      return;
+      goto out;
     }
 
   for (node = identities; node != NULL; node = node->next)
@@ -1618,6 +1618,9 @@ on_identities_listed (GoaIdentityManager *manager,
       else
         g_object_unref (object);
     }
+
+ out:
+  g_object_unref (self);
 }
 
 static void
@@ -1679,8 +1682,8 @@ on_got_client (GoaClient          *client,
 
   if (self->priv->client == NULL)
     {
-      goa_warning ("Could not create client: %s", error->message);
-      return;
+      g_warning ("Could not create client: %s", error->message);
+      goto out;
     }
 
   self->priv->accounts_manager = goa_client_get_manager (client);
@@ -1689,17 +1692,20 @@ on_got_client (GoaClient          *client,
 
   if (self->priv->identity_manager == NULL)
     {
-      goa_warning ("Could not create identity manager: %s", error->message);
-      return;
+      g_warning ("Could not create identity manager: %s", error->message);
+      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
@@ -1719,7 +1725,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]