glslstage: delete shader on finalize of stage
authorMichael Tretter <m.tretter@pengutronix.de>
Wed, 21 Oct 2020 09:42:54 +0000 (11:42 +0200)
committerMichael Tretter <m.tretter@pengutronix.de>
Wed, 21 Oct 2020 13:28:09 +0000 (15:28 +0200)
GLSLstage creates the glShader using glCreateShader, but never calls
glDeleteShader if the glShader is not used anymore. This forces the GL
library to keep the compiled shader around, because it might be used in
the future. Therefore, the glShader is leaked whenever a GLSLStage is
destroyed.

Fix the leak by deleting the glShader when finishing the GLSLStage.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/886>

gst-libs/gst/gl/gstglslstage.c

index 2b08adb..3e2d0e4 100644 (file)
@@ -75,11 +75,23 @@ G_DEFINE_TYPE_WITH_CODE (GstGLSLStage, gst_glsl_stage, GST_TYPE_OBJECT,
         "GLSL Stage"););
 
 static void
+_delete_shader (GstGLContext * context, GstGLSLStage * stage)
+{
+  GstGLSLStagePrivate *priv = stage->priv;
+
+  if (priv->handle)
+    priv->vtable.DeleteShader (priv->handle);
+}
+
+static void
 gst_glsl_stage_finalize (GObject * object)
 {
   GstGLSLStage *stage = GST_GLSL_STAGE (object);
   gint i;
 
+  gst_gl_context_thread_add (stage->context,
+      (GstGLContextThreadFunc) _delete_shader, stage);
+
   if (stage->context) {
     gst_object_unref (stage->context);
     stage->context = NULL;