commit 4a311fe868358fdb6991e7104901e86a011992f5
Author: Ognyan Tonchev <ognyan@axis.com>
Date:   Tue Sep 24 11:31:27 2013 +0200

    rtspconnection: Only create writesrc when it is actually needed
    
    Creating a GSoource and not attaching it to a context will cause
    a leak of it's child sources. That is why we create writesrc right
    before attaching it to a context.

diff --git a/gst-libs/gst/rtsp/gstrtspconnection.c b/gst-libs/gst/rtsp/gstrtspconnection.c
index 9041a33..1335756 100644
--- a/gst-libs/gst/rtsp/gstrtspconnection.c
+++ b/gst-libs/gst/rtsp/gstrtspconnection.c
@@ -2785,7 +2785,6 @@ struct _GstRTSPWatch
 
   GSource *readsrc;
   GSource *writesrc;
-  gboolean write_added;
 
   gboolean keep_running;
 
@@ -2975,19 +2974,12 @@ gst_rtsp_source_dispatch_write (GPollableOutputStream * stream,
       /* get a new message from the queue */
       rec = g_queue_pop_tail (watch->messages);
       if (rec == NULL) {
-        if (watch->write_added) {
+        if (watch->writesrc) {
           g_source_remove_child_source ((GSource *) watch, watch->writesrc);
-          watch->write_added = FALSE;
-
-          /* Need to create a new source as once removed/destroyed sources
-           * can't be attached again later */
           g_source_unref (watch->writesrc);
-          watch->writesrc =
-              g_pollable_output_stream_create_source (G_POLLABLE_OUTPUT_STREAM
-              (watch->conn->output_stream), NULL);
-          g_source_set_callback (watch->writesrc,
-              (GSourceFunc) gst_rtsp_source_dispatch_write, watch, NULL);
-          /* we add the write source when we actually have something to write */
+          watch->writesrc = NULL;
+          /* we create and add the write source again when we actually have
+           * something to write */
         }
         break;
       }
@@ -3147,11 +3139,9 @@ gst_rtsp_watch_reset (GstRTSPWatch * watch)
     g_source_unref (watch->readsrc);
   }
   if (watch->writesrc) {
-    if (watch->write_added) {
-      g_source_remove_child_source ((GSource *) watch, watch->writesrc);
-      watch->write_added = FALSE;
-    }
+    g_source_remove_child_source ((GSource *) watch, watch->writesrc);
     g_source_unref (watch->writesrc);
+    watch->writesrc = NULL;
   }
 
   if (watch->conn->input_stream) {
@@ -3165,16 +3155,8 @@ gst_rtsp_watch_reset (GstRTSPWatch * watch)
     watch->readsrc = NULL;
   }
 
-  if (watch->conn->output_stream) {
-    watch->writesrc =
-        g_pollable_output_stream_create_source (G_POLLABLE_OUTPUT_STREAM
-        (watch->conn->output_stream), NULL);
-    g_source_set_callback (watch->writesrc,
-        (GSourceFunc) gst_rtsp_source_dispatch_write, watch, NULL);
-    /* we add the write source when we actually have something to write */
-  } else {
-    watch->writesrc = NULL;
-  }
+  /* we create and add the write source when we actually have something to
+   * write */
 }
 
 /**
@@ -3343,9 +3325,13 @@ gst_rtsp_watch_write_data (GstRTSPWatch * watch, const guint8 * data,
   /* make sure the main context will now also check for writability on the
    * socket */
   context = ((GSource *) watch)->context;
-  if (!watch->write_added) {
+  if (!watch->writesrc) {
+    watch->writesrc =
+        g_pollable_output_stream_create_source (G_POLLABLE_OUTPUT_STREAM
+        (watch->conn->output_stream), NULL);
+    g_source_set_callback (watch->writesrc,
+        (GSourceFunc) gst_rtsp_source_dispatch_write, watch, NULL);
     g_source_add_child_source ((GSource *) watch, watch->writesrc);
-    watch->write_added = TRUE;
   }
 
   if (id != NULL)
