glfiter: Protect GstGLContext access
authorJan Schmidt <jan@centricular.com>
Thu, 5 Oct 2023 02:49:16 +0000 (13:49 +1100)
committerTim-Philipp Müller <tim@centricular.com>
Fri, 20 Oct 2023 10:02:02 +0000 (11:02 +0100)
The propose and decide allocation vfuncs are called directly from
basetransform and need to use the locked accessor function for
retrieving a reliable reference to the GstGLContext (if available)

Fixes spurious crashes on shutdown during pad reconfiguration

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

subprojects/gst-plugins-base/gst-libs/gst/gl/gstglfilter.c

index 895d77a..784241a 100644 (file)
@@ -803,7 +803,12 @@ gst_gl_filter_propose_allocation (GstBaseTransform * trans,
     GstQuery * decide_query, GstQuery * query)
 {
   GstGLFilter *filter = GST_GL_FILTER (trans);
-  GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
+  GstGLContext *context =
+      gst_gl_base_filter_get_gl_context (GST_GL_BASE_FILTER (filter));
+  if (context == NULL) {
+    return FALSE;
+  }
+
   GstCaps *caps;
   GstVideoInfo info;
   guint size;
@@ -843,22 +848,26 @@ gst_gl_filter_propose_allocation (GstBaseTransform * trans,
   if (context->gl_vtable->FenceSync)
     gst_query_add_allocation_meta (query, GST_GL_SYNC_META_API_TYPE, 0);
 
+  gst_object_unref (context);
   return TRUE;
 
   /* ERRORS */
 no_caps:
   {
     GST_DEBUG_OBJECT (trans, "no caps specified");
+    gst_object_unref (context);
     return FALSE;
   }
 invalid_caps:
   {
     GST_DEBUG_OBJECT (trans, "invalid caps specified");
+    gst_object_unref (context);
     return FALSE;
   }
 config_failed:
   {
     GST_DEBUG_OBJECT (trans, "failed setting config");
+    gst_object_unref (context);
     return FALSE;
   }
 }
@@ -866,7 +875,6 @@ config_failed:
 static gboolean
 gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
 {
-  GstGLContext *context;
   GstBufferPool *pool = NULL;
   GstStructure *config;
   GstCaps *caps;
@@ -882,7 +890,11 @@ gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
           query))
     return FALSE;
 
-  context = GST_GL_BASE_FILTER (trans)->context;
+  GstGLContext *context =
+      gst_gl_base_filter_get_gl_context (GST_GL_BASE_FILTER (trans));
+  if (context == NULL) {
+    return FALSE;
+  }
 
   if (gst_query_get_n_allocation_pools (query) > 0) {
     gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
@@ -920,6 +932,7 @@ gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
     gst_query_add_allocation_pool (query, pool, size, min, max);
 
   gst_object_unref (pool);
+  gst_object_unref (context);
 
   return TRUE;
 }