summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2020-04-28 23:16:18 +0300
committerSebastian Dröge <sebastian@centricular.com>2020-04-28 23:16:18 +0300
commit4188dbb99bd11807a6ee6e091a0eaa81ae08f066 (patch)
treef0590248e516d7aba18176810efbcc945ce78b36
parent680ddb9fd35b49c4db570943be192fc100641d5b (diff)
rtsp-client: Clean up watch/watch context and related state consistently
And assert that it was cleaned up properly before the client is finalized. If something is still around when the client is shut down then something went very wrong before. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/115>
-rw-r--r--gst/rtsp-server/rtsp-client.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/gst/rtsp-server/rtsp-client.c b/gst/rtsp-server/rtsp-client.c
index 9653be240a..a9572642d3 100644
--- a/gst/rtsp-server/rtsp-client.c
+++ b/gst/rtsp-server/rtsp-client.c
@@ -762,25 +762,15 @@ gst_rtsp_client_finalize (GObject * obj)
GST_INFO ("finalize client %p", client);
- if (priv->rtsp_ctrl_timeout_id != 0) {
- GST_DEBUG ("Killing leftover timeout GSource for client %p", client);
- g_source_destroy (g_main_context_find_source_by_id (priv->watch_context,
- priv->rtsp_ctrl_timeout_id));
- priv->rtsp_ctrl_timeout_id = 0;
- priv->rtsp_ctrl_timeout_cnt = 0;
- }
+ /* the watch and related state should be cleared before finalize
+ * as the watch actually holds a strong reference to the client */
+ g_assert (priv->watch == NULL);
+ g_assert (priv->watch_context == NULL);
+ g_assert (priv->rtsp_ctrl_timeout_id == 0);
- if (priv->watch)
- gst_rtsp_watch_set_flushing (priv->watch, TRUE);
gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
gst_rtsp_client_set_send_messages_func (client, NULL, NULL, NULL);
- if (priv->watch)
- g_source_destroy ((GSource *) priv->watch);
-
- if (priv->watch_context)
- g_main_context_unref (priv->watch_context);
-
/* all sessions should have been removed by now. We keep a ref to
* the client object for the session removed handler. The ref is
* dropped when the last session is removed from the list. */
@@ -1316,6 +1306,9 @@ gst_rtsp_client_close (GstRTSPClient * client)
gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
gst_rtsp_client_set_send_messages_func (client, NULL, NULL, NULL);
rtsp_ctrl_timeout_remove (priv);
+ }
+
+ if (priv->watch_context) {
g_main_context_unref (priv->watch_context);
priv->watch_context = NULL;
}
@@ -5049,6 +5042,12 @@ handle_tunnel (GstRTSPClient * client)
priv->watch = NULL;
gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
gst_rtsp_client_set_send_messages_func (client, NULL, NULL, NULL);
+ rtsp_ctrl_timeout_remove (priv);
+ }
+
+ if (priv->watch_context) {
+ g_main_context_unref (priv->watch_context);
+ priv->watch_context = NULL;
}
return GST_RTSP_STS_OK;
@@ -5145,8 +5144,15 @@ client_watch_notify (GstRTSPClient * client)
GST_INFO ("client %p: watch destroyed", client);
priv->watch = NULL;
/* remove all sessions if the media says so and so drop the extra client ref */
+ gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
+ gst_rtsp_client_set_send_messages_func (client, NULL, NULL, NULL);
rtsp_ctrl_timeout_remove (priv);
gst_rtsp_client_session_filter (client, cleanup_session, &closed);
+ if (priv->watch_context) {
+ g_main_context_unref (priv->watch_context);
+ priv->watch_context = NULL;
+ }
+
if (closed)
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_CLOSED], 0, NULL);
g_object_unref (client);