[Mesa-dev] [PATCH] mesa: Prevent repeated glDeleteShader() from blowing away our refcounts.

Brian Paul brianp at vmware.com
Thu Jul 19 14:58:05 PDT 2012


On 07/19/2012 02:41 PM, Kenneth Graunke wrote:
> Calling glDeleteShader() should mark shaders as pending for deletion,
> but shouldn't decrement the refcount every time.  Otherwise, repeated
> glDeleteShader() is not safe.
>
> This is particularly bad since glDeleteProgram() frees shaders: if you
> first call glDeleteShader() on the shaders attached to the program (thus
> decrementing the refcount), then called glDeleteProgram(), it would try
> to free them again (decrementing the refcount another time), causing
> a refcount>  0 assertion to fail.
>
> Similar to commit d950a778.


Candidate for the 8.0 branch?


> Signed-off-by: Kenneth Graunke<kenneth at whitecape.org>
> ---
>   src/mesa/main/shaderapi.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
> index 6927368..7c97a63 100644
> --- a/src/mesa/main/shaderapi.c
> +++ b/src/mesa/main/shaderapi.c
> @@ -346,10 +346,12 @@ delete_shader(struct gl_context *ctx, GLuint shader)
>      if (!sh)
>         return;
>
> -   sh->DeletePending = GL_TRUE;
> +   if (!sh->DeletePending) {
> +      sh->DeletePending = GL_TRUE;
>
> -   /* effectively, decr sh's refcount */
> -   _mesa_reference_shader(ctx,&sh, NULL);
> +      /* effectively, decr sh's refcount */
> +      _mesa_reference_shader(ctx,&sh, NULL);
> +   }
>   }
>
>


Reviewed-by: Brian Paul <brianp at vmware.com>


More information about the mesa-dev mailing list