diff --git a/gst-libs/gst/gl/gstglshader.c b/gst-libs/gst/gl/gstglshader.c index cbd300d4a0..218c0a8f54 100644 --- a/gst-libs/gst/gl/gstglshader.c +++ b/gst-libs/gst/gl/gstglshader.c @@ -197,6 +197,7 @@ _new_with_stages_va_list (GstGLContext * context, GError ** error, { GstGLShader *shader; GstGLSLStage *stage; + gboolean to_unref_and_out = FALSE; g_return_val_if_fail (GST_IS_GL_CONTEXT (context), NULL); @@ -204,18 +205,29 @@ _new_with_stages_va_list (GstGLContext * context, GError ** error, shader->context = gst_object_ref (context); while ((stage = va_arg (varargs, GstGLSLStage *))) { + if (to_unref_and_out) { + gst_object_unref (stage); + continue; + } + if (!gst_glsl_stage_compile (stage, error)) { - gst_object_unref (shader); - return NULL; + gst_object_unref (stage); + to_unref_and_out = TRUE; + continue; } if (!gst_gl_shader_attach (shader, stage)) { g_set_error (error, GST_GLSL_ERROR, GST_GLSL_ERROR_PROGRAM, "Failed to attach stage to program"); - gst_object_unref (shader); - return NULL; + to_unref_and_out = TRUE; + continue; } } + if (to_unref_and_out) { + gst_object_unref (shader); + return NULL; + } + return shader; } diff --git a/gst-libs/gst/gl/gstglutils.c b/gst-libs/gst/gl/gstglutils.c index d80aaab58c..ae48d7c312 100644 --- a/gst-libs/gst/gl/gstglutils.c +++ b/gst-libs/gst/gl/gstglutils.c @@ -397,6 +397,7 @@ _compile_shader (GstGLContext * context, struct _compile_shader *data) GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, data->vertex_src); if (!gst_glsl_stage_compile (vert, &error)) { GST_ERROR_OBJECT (vert, "%s", error->message); + gst_object_unref (vert); gst_object_unref (shader); return; } @@ -413,6 +414,7 @@ _compile_shader (GstGLContext * context, struct _compile_shader *data) data->fragment_src); if (!gst_glsl_stage_compile (frag, &error)) { GST_ERROR_OBJECT (frag, "%s", error->message); + gst_object_unref (frag); gst_object_unref (shader); return; }