[Telepathy-commits] [telepathy-salut/master] Fix reference counts in SalutContact->SalutConnection and in SalutXmppConnectionManager
Alban Crequy
alban.crequy at collabora.co.uk
Tue Nov 25 03:59:28 PST 2008
---
src/salut-contact.c | 7 +++++++
src/salut-xmpp-connection-manager.c | 14 +++++++++++++-
2 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/src/salut-contact.c b/src/salut-contact.c
index 8256782..fdb492b 100644
--- a/src/salut-contact.c
+++ b/src/salut-contact.c
@@ -166,6 +166,7 @@ salut_contact_set_property (GObject *object,
{
case PROP_CONNECTION:
self->connection = g_value_get_object (value);
+ g_object_ref (self->connection);
break;
case PROP_NAME:
self->name = g_value_dup_string (value);
@@ -294,6 +295,12 @@ salut_contact_dispose (GObject *object)
if (self->handle != 0)
tp_handle_unref (contact_repo, self->handle);
+ if (self->connection != NULL)
+ {
+ g_object_unref (self->connection);
+ self->connection = NULL;
+ }
+
if (G_OBJECT_CLASS (salut_contact_parent_class)->dispose)
G_OBJECT_CLASS (salut_contact_parent_class)->dispose (object);
}
diff --git a/src/salut-xmpp-connection-manager.c b/src/salut-xmpp-connection-manager.c
index 10371f3..40d1be1 100644
--- a/src/salut-xmpp-connection-manager.c
+++ b/src/salut-xmpp-connection-manager.c
@@ -547,8 +547,19 @@ connection_transport_disconnected_cb (GibberLLTransport *transport,
DEBUG ("Connection transport disconnected");
data.self = self;
data.transport = transport;
+
+ /* remove_connection_having_transport() will unref GibberXmppConnection (the
+ * key of the hash) and unref SalutContact (the value of the hash). If
+ * SalutContact is freed at this step, this will unref SalutConnection, and
+ * may unref and free this SalutXmppConnectionManager. We don't want
+ * SalutXmppConnectionManager to be freed while we are still in the foreach
+ * loop. Hence the ref and unref of priv->connection, in order to free
+ * everything after the foreach loop.
+ * */
+ g_object_ref (priv->connection);
g_hash_table_foreach_remove (priv->connections,
remove_connection_having_transport, &data);
+ g_object_unref (priv->connection);
}
static void
@@ -1300,7 +1311,8 @@ create_new_outgoing_connection (SalutXmppConnectionManager *self,
* open it */
DEBUG ("waiting for remote contact (%s) open the connection",
contact->name);
- g_hash_table_insert (priv->outgoing_pending_connections, connection,
+ g_hash_table_insert (priv->outgoing_pending_connections,
+ g_object_ref (connection),
g_object_ref (contact));
add_outgoing_timeout (self, connection, contact);
--
1.5.6.5
More information about the Telepathy-commits
mailing list