udpsrc: protect cancellable from unlock/unlock_stop race
authorRobert Rosengren <robertr@axis.com>
Wed, 13 Nov 2024 14:49:57 +0000 (15:49 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 15 Nov 2024 12:39:16 +0000 (12:39 +0000)
Protect cancellable from simultaneous unlock and unlock_stop calls from
basesrc class.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7897>

subprojects/gst-plugins-good/gst/udp/gstudpsrc.c

index 428555d252f55ebd1bec79c90d1e1d537f6b52c6..7d9b16a9d8b4066803d2a27619ba3996b6d90bdf 100644 (file)
@@ -932,8 +932,7 @@ gst_udpsrc_free_cancellable (GstUDPSrc * src)
     g_cancellable_release_fd (src->cancellable);
     src->made_cancel_fd = FALSE;
   }
-  g_object_unref (src->cancellable);
-  src->cancellable = NULL;
+  g_clear_object (&src->cancellable);
 }
 
 static GstFlowReturn
@@ -1945,7 +1944,9 @@ gst_udpsrc_unlock (GstBaseSrc * bsrc)
   src = GST_UDPSRC (bsrc);
 
   GST_LOG_OBJECT (src, "Flushing");
+  GST_OBJECT_LOCK (src);
   g_cancellable_cancel (src->cancellable);
+  GST_OBJECT_UNLOCK (src);
 
   return TRUE;
 }
@@ -1959,8 +1960,10 @@ gst_udpsrc_unlock_stop (GstBaseSrc * bsrc)
 
   GST_LOG_OBJECT (src, "No longer flushing");
 
+  GST_OBJECT_LOCK (src);
   gst_udpsrc_free_cancellable (src);
   gst_udpsrc_create_cancellable (src);
+  GST_OBJECT_UNLOCK (src);
 
   return TRUE;
 }