From 3cfe88632fc4896dcf4107baae06c9f165d54bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20J=C3=B6nsson?= Date: Tue, 2 Apr 2019 08:05:03 +0200 Subject: [PATCH] rtsp_server: Free thread pool before clean transport cache If not waiting for free thread pool before clean transport caches, there can be a crash if a thread is executing in transport list loop in function send_tcp_message. Also add a check if priv->send_pool in on_message_sent to avoid that a new thread is pushed during wait of free thread pool. This is possible since when waiting for free thread pool mutex have to be unlocked. --- gst/rtsp-server/rtsp-stream.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gst/rtsp-server/rtsp-stream.c b/gst/rtsp-server/rtsp-stream.c index e6721a2d8a..e6ba6c1d59 100644 --- a/gst/rtsp-server/rtsp-stream.c +++ b/gst/rtsp-server/rtsp-stream.c @@ -3836,6 +3836,16 @@ gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin, if (priv->transports != NULL) goto transports_not_removed; + if (priv->send_pool) { + GThreadPool *slask; + + slask = priv->send_pool; + priv->send_pool = NULL; + g_mutex_unlock (&priv->lock); + g_thread_pool_free (slask, TRUE, TRUE); + g_mutex_lock (&priv->lock); + } + clear_tr_cache (priv, TRUE); clear_tr_cache (priv, FALSE); @@ -4426,8 +4436,10 @@ on_message_sent (gpointer user_data) if (idx != -1) { gint dummy; - GST_DEBUG_OBJECT (stream, "start thread"); - g_thread_pool_push (priv->send_pool, &dummy, NULL); + if (priv->send_pool) { + GST_DEBUG_OBJECT (stream, "start thread"); + g_thread_pool_push (priv->send_pool, &dummy, NULL); + } } g_mutex_unlock (&priv->lock);