[telepathy-glib-0.18] telepathy-glib: Do not use _tp_connection_lookup_contact() outside contact.c
Xavier Claessens
xclaesse at kemper.freedesktop.org
Mon Apr 16 09:28:40 PDT 2012
Module: telepathy-glib
Branch: telepathy-glib-0.18
Commit: 57e23d6d7788498061349649e9b4bccf9ea7bf7b
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=57e23d6d7788498061349649e9b4bccf9ea7bf7b
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 6e88061..81a2a49 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