[gtk: 1/2] gl: Fix implicit leaking of shader object
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 1/2] gl: Fix implicit leaking of shader object
- Date: Tue, 29 Dec 2020 16:58:56 +0000 (UTC)
commit 34ffdc6e3f5f1548ac2ded575cdd0e391cf9b66a
Author: xndcn <xndchn gmail com>
Date: Tue Dec 29 22:29:37 2020 +0800
gl: Fix implicit leaking of shader object
According to OpenGL spec, a shader object will only be flagged
for deletion unless it has been detached; when a program object
is deleted, those shader objects attached to it will be detached
but not deleted unless they have already been flagged for deletion.
So we shall detach a shader object before it is deleted, and delete
it before the program object is deleted best.
demos/gtk-demo/gtkgears.c | 2 ++
gdk/gdkgl.c | 3 +++
gsk/gl/gskglshaderbuilder.c | 7 ++-----
tests/gtkgears.c | 2 ++
4 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/demos/gtk-demo/gtkgears.c b/demos/gtk-demo/gtkgears.c
index ba52ddd1b0..1463cbb6b5 100644
--- a/demos/gtk-demo/gtkgears.c
+++ b/demos/gtk-demo/gtkgears.c
@@ -787,6 +787,8 @@ gtk_gears_realize (GtkWidget *widget)
glLinkProgram(program);
glGetProgramInfoLog(program, sizeof msg, NULL, msg);
g_debug ("program info: %s\n", msg);
+ glDetachShader (program, v);
+ glDetachShader (program, f);
glDeleteShader (v);
glDeleteShader (f);
diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c
index 56dce18333..5ebd2138d8 100644
--- a/gdk/gdkgl.c
+++ b/gdk/gdkgl.c
@@ -107,6 +107,9 @@ make_program (GdkGLContextProgram *program,
glLinkProgram (program->program);
+ glDetachShader (program->program, vertex_shader);
+ glDetachShader (program->program, fragment_shader);
+
glDeleteShader (vertex_shader);
glDeleteShader (fragment_shader);
diff --git a/gsk/gl/gskglshaderbuilder.c b/gsk/gl/gskglshaderbuilder.c
index 1a4ddc301b..75aef60e7d 100644
--- a/gsk/gl/gskglshaderbuilder.c
+++ b/gsk/gl/gskglshaderbuilder.c
@@ -232,6 +232,8 @@ gsk_gl_shader_builder_create_program (GskGLShaderBuilder *self,
glBindAttribLocation (program_id, 0, "aPosition");
glBindAttribLocation (program_id, 1, "vUv");
glLinkProgram (program_id);
+ glDetachShader (program_id, vertex_id);
+ glDetachShader (program_id, fragment_id);
glGetProgramiv (program_id, GL_LINK_STATUS, &status);
if (status == GL_FALSE)
@@ -252,14 +254,9 @@ gsk_gl_shader_builder_create_program (GskGLShaderBuilder *self,
glDeleteProgram (program_id);
program_id = -1;
-
- goto out;
}
- glDetachShader (program_id, vertex_id);
glDeleteShader (vertex_id);
-
- glDetachShader (program_id, fragment_id);
glDeleteShader (fragment_id);
out:
diff --git a/tests/gtkgears.c b/tests/gtkgears.c
index 5f5686c883..2ece67dcf9 100644
--- a/tests/gtkgears.c
+++ b/tests/gtkgears.c
@@ -787,6 +787,8 @@ gtk_gears_realize (GtkWidget *widget)
glLinkProgram(program);
glGetProgramInfoLog(program, sizeof msg, NULL, msg);
g_print ("program info: %s\n", msg);
+ glDetachShader (program, v);
+ glDetachShader (program, f);
glDeleteShader (v);
glDeleteShader (f);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]