adaptivedemux2: Fix a small race on shutdown

Make sure gst_adaptive_demux_loop_cancel_call()
never tries to operate on an invalidated main context. Make
sure to clear the main context pointer while holding the lock,
and to check it in gst_adaptive_demux_loop_cancel_call()

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2847>
This commit is contained in:
Jan Schmidt 2022-08-04 23:54:27 +10:00 committed by Tim-Philipp Müller
parent cf64c9f588
commit b7e662f400

View file

@ -215,11 +215,12 @@ _gst_adaptive_demux_loop_thread (GstAdaptiveDemuxLoop * loop)
loop->loop = NULL;
g_cond_broadcast (&loop->cond);
g_mutex_unlock (&loop->lock);
g_main_context_unref (loop->context);
loop->context = NULL;
g_mutex_unlock (&loop->lock);
gst_adaptive_demux_loop_unref (loop);
return NULL;
@ -380,12 +381,13 @@ gst_adaptive_demux_loop_call_delayed (GstAdaptiveDemuxLoop * loop,
void
gst_adaptive_demux_loop_cancel_call (GstAdaptiveDemuxLoop * loop, guint cb_id)
{
GSource *s;
g_mutex_lock (&loop->lock);
s = g_main_context_find_source_by_id (loop->context, cb_id);
if (s)
g_source_destroy (s);
if (loop->context) {
GSource *s = g_main_context_find_source_by_id (loop->context, cb_id);
if (s)
g_source_destroy (s);
}
g_mutex_unlock (&loop->lock);
}