[Telepathy-commits] [telepathy-salut/master] tube-stream: data_received_cb ref the transport to keep it artificially alive if needed

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Thu Dec 18 06:33:40 PST 2008


---
 src/tube-stream.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/tube-stream.c b/src/tube-stream.c
index 5a58c55..a23d6a1 100644
--- a/src/tube-stream.c
+++ b/src/tube-stream.c
@@ -1379,11 +1379,20 @@ data_received_cb (GibberBytestreamIface *bytestream,
   transport = g_hash_table_lookup (priv->bytestream_to_transport, bytestream);
   g_assert (transport != NULL);
 
+  /* If something goes wrong when trying to write the data on the transport,
+   * it could be disconnected, causing its removal from the hash tables.
+   * When removed, the transport would be destroyed as the hash tables keep a
+   * ref on it and so we'll call _buffer_is_empty on a destroyed transport.
+   * We avoid that by reffing the transport between the 2 calls so we keep it
+   * artificially alive if needed. */
+  g_object_ref (transport);
   if (!gibber_transport_send (transport, (const guint8 *) data->str, data->len,
       &error))
   {
     DEBUG ("sending failed: %s", error->message);
     g_error_free (error);
+    g_object_unref (transport);
+    return;
   }
 
   if (!gibber_transport_buffer_is_empty (transport))
@@ -1392,6 +1401,7 @@ data_received_cb (GibberBytestreamIface *bytestream,
       DEBUG ("tube buffer isn't empty. Block the bytestream");
       gibber_bytestream_iface_block_reading (bytestream, TRUE);
     }
+  g_object_unref (transport);
 }
 
 SalutTubeStream *
-- 
1.5.6.5



More information about the Telepathy-commits mailing list