mesa: free shader program data before deleting shader objects.
authorBrian Paul <brian.paul@tungstengraphics.com>
Wed, 7 May 2008 14:56:08 +0000 (08:56 -0600)
committerBrian Paul <brian.paul@tungstengraphics.com>
Wed, 7 May 2008 14:56:08 +0000 (08:56 -0600)
Picked from master.
Fixes mem corruption seen when glean/api2 test exits.

src/mesa/main/context.c

index b9053344b26b691a87ee883a1687b2362a156300..893c79f28ca2d57b3d7e75b81c46f85ef75b0439 100755 (executable)
@@ -630,6 +630,21 @@ delete_arrayobj_cb(GLuint id, void *data, void *userData)
    _mesa_delete_array_object(ctx, arrayObj);
 }
 
+/**
+ * Callback for freeing shader program data. Call it before delete_shader_cb
+ * to avoid memory access error.
+ */
+static void
+free_shader_program_data_cb(GLuint id, void *data, void *userData)
+{
+   GLcontext *ctx = (GLcontext *) userData;
+   struct gl_shader_program *shProg = (struct gl_shader_program *) data;
+
+   if (shProg->Type == GL_SHADER_PROGRAM_MESA) {
+       _mesa_free_shader_program_data(ctx, shProg);
+   }
+}
+
 /**
  * Callback for deleting shader and shader programs objects.
  * Called by _mesa_HashDeleteAll().
@@ -714,6 +729,7 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
    _mesa_DeleteHashTable(ss->ArrayObjects);
 
 #if FEATURE_ARB_shader_objects
+   _mesa_HashWalk(ss->ShaderObjects, free_shader_program_data_cb, ctx);
    _mesa_HashDeleteAll(ss->ShaderObjects, delete_shader_cb, ctx);
    _mesa_DeleteHashTable(ss->ShaderObjects);
 #endif