summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOgnyan Tonchev <ognyan@axis.com>2013-09-24 12:10:00 +0200
committerSebastian Dröge <slomo@circular-chaos.org>2013-09-24 12:10:00 +0200
commit8ba90931aed21edd44ddda515665312e49c6b088 (patch)
tree2c6b55969f868cbea67b2383e7d64c7edc0f9b5d
parent663f71a5ddfcf75adbc857fb1c275f82e6e5dbe9 (diff)
rtspconnection: Only create writesrc when it is actually needed
Creating a GSource 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. https://bugzilla.gnome.org/show_bug.cgi?id=708667
-rw-r--r--gst-libs/gst/rtsp/gstrtspconnection.c42
1 files changed, 14 insertions, 28 deletions
diff --git a/gst-libs/gst/rtsp/gstrtspconnection.c b/gst-libs/gst/rtsp/gstrtspconnection.c
index 9041a3305..1335756cf 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)