[libgdata] core: Fix race condition in upload thread instantiation



commit 288391e657c890338bf49b00228171b84d8c90be
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Aug 1 17:52:54 2013 +0200

    core: Fix race condition in upload thread instantiation
    
    The upload thread takes a reference on the GDataUploadStream, but the
    stream could be finalised while the thread is still being created;
    hence once the thread main function starts and calls g_object_ref(),
    the GDataUploadStream has already been destroyed.
    
    Move the g_object_ref() call to before the thread instantiation to
    fix this.

 gdata/gdata-upload-stream.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/gdata/gdata-upload-stream.c b/gdata/gdata-upload-stream.c
index 69a347e..2430641 100644
--- a/gdata/gdata-upload-stream.c
+++ b/gdata/gdata-upload-stream.c
@@ -1128,8 +1128,6 @@ upload_thread (GDataUploadStream *self)
 {
        GDataUploadStreamPrivate *priv = self->priv;
 
-       g_object_ref (self);
-
        g_assert (priv->cancellable != NULL);
 
        while (TRUE) {
@@ -1268,6 +1266,7 @@ finished_outer:
        g_cond_signal (&(priv->finished_cond));
        g_mutex_unlock (&(priv->response_mutex));
 
+       /* Referenced in create_network_thread(). */
        g_object_unref (self);
 
        return NULL;
@@ -1279,6 +1278,7 @@ create_network_thread (GDataUploadStream *self, GError **error)
        GDataUploadStreamPrivate *priv = self->priv;
 
        g_assert (priv->network_thread == NULL);
+       g_object_ref (self); /* ownership transferred to thread */
        priv->network_thread = g_thread_try_new ("upload-thread", (GThreadFunc) upload_thread, self, error);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]