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
This commit is contained in:
Ognyan Tonchev 2013-09-24 12:10:00 +02:00 committed by Sebastian Dröge
parent 663f71a5dd
commit 8ba90931ae

View file

@ -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)