glvideomixer: Keep a reference to the underlying pad
authorThibault Saunier <tsaunier@igalia.com>
Fri, 10 Feb 2023 11:20:38 +0000 (08:20 -0300)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 15 Feb 2023 03:11:03 +0000 (03:11 +0000)
There was cases where we were accessing the pad while it was already
destroyed. Ensure it can't happen by owning a ref on it.

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

subprojects/gst-plugins-base/ext/gl/gstglvideomixer.c

index c08e7a0..de08888 100644 (file)
@@ -200,6 +200,7 @@ static void gst_gl_video_mixer_input_set_property (GObject * object,
     guint prop_id, const GValue * value, GParamSpec * pspec);
 static gboolean gst_gl_video_mixer_src_event (GstAggregator * agg,
     GstEvent * event);
+static void gst_gl_video_mixer_input_dispose (GObject * object);
 
 typedef struct _GstGLVideoMixerInput GstGLVideoMixerInput;
 typedef GstGhostPadClass GstGLVideoMixerInputClass;
@@ -229,6 +230,7 @@ gst_gl_video_mixer_input_class_init (GstGLVideoMixerInputClass * klass)
 
   gobject_class->set_property = gst_gl_video_mixer_input_set_property;
   gobject_class->get_property = gst_gl_video_mixer_input_get_property;
+  gobject_class->dispose = gst_gl_video_mixer_input_dispose;
 
   g_object_class_install_property (gobject_class, PROP_INPUT_ZORDER,
       g_param_spec_uint ("zorder", "Z-Order", "Z Order of the picture",
@@ -394,6 +396,14 @@ gst_gl_video_mixer_input_set_property (GObject * object, guint prop_id,
     g_object_set_property (G_OBJECT (self->mixer_pad), pspec->name, value);
 }
 
+static void
+gst_gl_video_mixer_input_dispose (GObject * object)
+{
+  GstGLVideoMixerInput *self = (GstGLVideoMixerInput *) object;
+
+  gst_clear_object (&self->mixer_pad);
+}
+
 static GstGhostPad *
 _create_video_mixer_input (GstGLMixerBin * self, GstPad * mixer_pad)
 {
@@ -424,7 +434,7 @@ _create_video_mixer_input (GstGLMixerBin * self, GstPad * mixer_pad)
   ADD_BINDING (mixer_pad, input, "blend-constant-color-alpha");
 #undef ADD_BINDING
 
-  input->mixer_pad = mixer_pad;
+  input->mixer_pad = gst_object_ref (mixer_pad);
 
   return GST_GHOST_PAD (input);
 }