rtsp_server: Free thread pool before clean transport cache
authorGöran Jönsson <goranjn@axis.com>
Tue, 2 Apr 2019 06:05:03 +0000 (08:05 +0200)
committerGöran Jönsson <goranjn@axis.com>
Thu, 11 Apr 2019 06:02:52 +0000 (08:02 +0200)
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

index e6721a2..e6ba6c1 100644 (file)
@@ -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);