harness: Make sure pad functions are not called after teardown
authorStian Selnes <stian@pexip.com>
Mon, 28 May 2018 08:57:13 +0000 (10:57 +0200)
committerHavard Graff <havard.graff@gmail.com>
Thu, 13 Jun 2019 07:45:03 +0000 (09:45 +0200)
For the query function there's a risk that the function may be called
after the harness has been teared down. Since the function accesses a
pointer to the harness via the pad's data, the harness must protect
itself against this.

Event and chain function is also handled for constistency, although
they don't have the same problem since the gstpad.c checks whether the
pad is flushing before calling these.

libs/gst/check/gstharness.c

index b276100..af4d272 100644 (file)
@@ -1055,6 +1055,14 @@ gst_harness_teardown (GstHarness * h)
     g_free (priv->element_sinkpad_name);
 
     gst_pad_set_active (h->srcpad, FALSE);
+
+    /* Make sure our funcs are not called after harness is teared down since
+     * they try to access this harness through pad data */
+    GST_PAD_STREAM_LOCK (h->srcpad);
+    gst_pad_set_event_function (h->srcpad, NULL);
+    gst_pad_set_query_function (h->srcpad, NULL);
+    GST_PAD_STREAM_UNLOCK (h->srcpad);
+
     gst_object_unref (h->srcpad);
 
     g_async_queue_unref (priv->src_event_queue);
@@ -1066,6 +1074,15 @@ gst_harness_teardown (GstHarness * h)
     g_free (priv->element_srcpad_name);
 
     gst_pad_set_active (h->sinkpad, FALSE);
+
+    /* Make sure our funcs are not called after harness is teared down since
+     * they try to access this harness through pad data */
+    GST_PAD_STREAM_LOCK (h->sinkpad);
+    gst_pad_set_chain_function (h->sinkpad, NULL);
+    gst_pad_set_event_function (h->sinkpad, NULL);
+    gst_pad_set_query_function (h->sinkpad, NULL);
+    GST_PAD_STREAM_UNLOCK (h->sinkpad);
+
     gst_object_unref (h->sinkpad);
 
     g_async_queue_unref (priv->buffer_queue);