[next] telepathy-glib: Do not use _tp_connection_lookup_contact() outside contact.c

Simon McVittie smcv at kemper.freedesktop.org
Wed Apr 25 07:26:04 PDT 2012


Module: telepathy-glib
Branch: next
Commit: a75257708a4766a5e1fcbf19d1d7d5bf588eab91
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=a75257708a4766a5e1fcbf19d1d7d5bf588eab91

Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date:   Mon Apr 16 17:42:33 2012 +0200

Do not use _tp_connection_lookup_contact() outside contact.c

That function is dangerous because it does not guarantee that the returned TpContact
has an identifier set.

In the case a TpContact is being created with tp_connection_get_contacts_by_id(),
the first step is to inspect its handle and then create the TpContact object
*without* giving its ID. The id will be set later once we got the contact attributes.

If _tp_connection_lookup_contact() is called for the same handle/id between
the moment the TpContact is created and the moment it sets its attributes, then
a contact with no identifier is returned.

---

 telepathy-glib/call-channel.c          |    7 ++++---
 telepathy-glib/simple-client-factory.c |    5 +++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/telepathy-glib/call-channel.c b/telepathy-glib/call-channel.c
index 4404aaa..cdd619d 100644
--- a/telepathy-glib/call-channel.c
+++ b/telepathy-glib/call-channel.c
@@ -77,7 +77,7 @@ struct _TpCallChannelPrivate
   GHashTable *state_details;
   TpCallStateReason *state_reason;
   gboolean hardware_streaming;
-  /* TpHandle -> TpCallMemberFlags */
+  /* TpContact -> TpCallMemberFlags */
   GHashTable *members;
   gboolean initial_audio;
   gboolean initial_video;
@@ -270,14 +270,15 @@ _tp_call_members_convert_array (TpConnection *connection,
       TpContact *contact;
 
       /* The contact is supposed to already exists */
-      contact = _tp_connection_lookup_contact (connection, handle);
+      contact = tp_connection_dup_contact_if_possible (connection,
+          handle, NULL);
       if (contact == NULL)
         {
           DEBUG ("No TpContact found for handle %u", handle);
           continue;
         }
 
-      g_ptr_array_add (result, g_object_ref (contact));
+      g_ptr_array_add (result, contact);
     }
 
   return result;
diff --git a/telepathy-glib/simple-client-factory.c b/telepathy-glib/simple-client-factory.c
index 57fb9af..fa8fd04 100644
--- a/telepathy-glib/simple-client-factory.c
+++ b/telepathy-glib/simple-client-factory.c
@@ -849,9 +849,10 @@ tp_simple_client_factory_ensure_contact (TpSimpleClientFactory *self,
   g_return_val_if_fail (handle != 0, NULL);
   g_return_val_if_fail (identifier != NULL, NULL);
 
-  contact = _tp_connection_lookup_contact (connection, handle);
+  contact = tp_connection_dup_contact_if_possible (connection,
+      handle, identifier);
   if (contact != NULL)
-    return g_object_ref (contact);
+    return contact;
 
   contact = TP_SIMPLE_CLIENT_FACTORY_GET_CLASS (self)->create_contact (self,
       connection, handle, identifier);



More information about the telepathy-commits mailing list