From 21841f0ae5ca9b55ee23ecaa3513e91b6752aa16 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 14 Aug 2004 14:28:11 +0000 Subject: fix some memory leaks (bug #1002030) --- src/mesa/shader/program.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'src/mesa/shader/program.c') diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 18bebd227a..daec9252ff 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -47,7 +47,7 @@ /** - * Init context's program state + * Init context's vertex/fragment program state */ void _mesa_init_program(GLcontext *ctx) @@ -79,6 +79,32 @@ _mesa_init_program(GLcontext *ctx) } +/** + * Free a context's vertex/fragment program state + */ +void +_mesa_free_program_data(GLcontext *ctx) +{ +#if FEATURE_NV_vertex_program + if (ctx->VertexProgram.Current) { + ctx->VertexProgram.Current->Base.RefCount--; + if (ctx->VertexProgram.Current->Base.RefCount <= 0) + ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base)); + } +#endif +#if FEATURE_NV_fragment_program + if (ctx->FragmentProgram.Current) { + ctx->FragmentProgram.Current->Base.RefCount--; + if (ctx->FragmentProgram.Current->Base.RefCount <= 0) + ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base)); + } +#endif + _mesa_free((void *) ctx->Program.ErrorString); +} + + + + /** * Set the vertex/fragment program error state (position and error string). * This is generally called from within the parsers. @@ -222,15 +248,16 @@ _mesa_delete_program(GLcontext *ctx, struct program *prog) struct vertex_program *vprog = (struct vertex_program *) prog; if (vprog->Instructions) _mesa_free(vprog->Instructions); + if (vprog->Parameters) + _mesa_free_parameter_list(vprog->Parameters); } else if (prog->Target == GL_FRAGMENT_PROGRAM_NV || prog->Target == GL_FRAGMENT_PROGRAM_ARB) { struct fragment_program *fprog = (struct fragment_program *) prog; if (fprog->Instructions) _mesa_free(fprog->Instructions); - if (fprog->Parameters) { + if (fprog->Parameters) _mesa_free_parameter_list(fprog->Parameters); - } } _mesa_free(prog); } -- cgit v1.2.3