mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 09:10:36 +00:00
glshader: properly unref the stages on failure
When failing in the varargs functions, all the stage objects not handled need to be unreffed to prevent a leak.
This commit is contained in:
parent
1f35fcf06d
commit
117fc0409a
2 changed files with 18 additions and 4 deletions
|
@ -197,6 +197,7 @@ _new_with_stages_va_list (GstGLContext * context, GError ** error,
|
||||||
{
|
{
|
||||||
GstGLShader *shader;
|
GstGLShader *shader;
|
||||||
GstGLSLStage *stage;
|
GstGLSLStage *stage;
|
||||||
|
gboolean to_unref_and_out = FALSE;
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), NULL);
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), NULL);
|
||||||
|
|
||||||
|
@ -204,17 +205,28 @@ _new_with_stages_va_list (GstGLContext * context, GError ** error,
|
||||||
shader->context = gst_object_ref (context);
|
shader->context = gst_object_ref (context);
|
||||||
|
|
||||||
while ((stage = va_arg (varargs, GstGLSLStage *))) {
|
while ((stage = va_arg (varargs, GstGLSLStage *))) {
|
||||||
|
if (to_unref_and_out) {
|
||||||
|
gst_object_unref (stage);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!gst_glsl_stage_compile (stage, error)) {
|
if (!gst_glsl_stage_compile (stage, error)) {
|
||||||
gst_object_unref (shader);
|
gst_object_unref (stage);
|
||||||
return NULL;
|
to_unref_and_out = TRUE;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (!gst_gl_shader_attach (shader, stage)) {
|
if (!gst_gl_shader_attach (shader, stage)) {
|
||||||
g_set_error (error, GST_GLSL_ERROR, GST_GLSL_ERROR_PROGRAM,
|
g_set_error (error, GST_GLSL_ERROR, GST_GLSL_ERROR_PROGRAM,
|
||||||
"Failed to attach stage to program");
|
"Failed to attach stage to program");
|
||||||
|
to_unref_and_out = TRUE;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (to_unref_and_out) {
|
||||||
gst_object_unref (shader);
|
gst_object_unref (shader);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
|
@ -397,6 +397,7 @@ _compile_shader (GstGLContext * context, struct _compile_shader *data)
|
||||||
GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, data->vertex_src);
|
GST_GLSL_PROFILE_ES | GST_GLSL_PROFILE_COMPATIBILITY, data->vertex_src);
|
||||||
if (!gst_glsl_stage_compile (vert, &error)) {
|
if (!gst_glsl_stage_compile (vert, &error)) {
|
||||||
GST_ERROR_OBJECT (vert, "%s", error->message);
|
GST_ERROR_OBJECT (vert, "%s", error->message);
|
||||||
|
gst_object_unref (vert);
|
||||||
gst_object_unref (shader);
|
gst_object_unref (shader);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -413,6 +414,7 @@ _compile_shader (GstGLContext * context, struct _compile_shader *data)
|
||||||
data->fragment_src);
|
data->fragment_src);
|
||||||
if (!gst_glsl_stage_compile (frag, &error)) {
|
if (!gst_glsl_stage_compile (frag, &error)) {
|
||||||
GST_ERROR_OBJECT (frag, "%s", error->message);
|
GST_ERROR_OBJECT (frag, "%s", error->message);
|
||||||
|
gst_object_unref (frag);
|
||||||
gst_object_unref (shader);
|
gst_object_unref (shader);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue