mesa: Free all shader program data before deleting all
authorXiang, Haihao <haihao.xiang@intel.com>
Mon, 31 Mar 2008 09:02:47 +0000 (17:02 +0800)
committerXiang, Haihao <haihao.xiang@intel.com>
Mon, 31 Mar 2008 09:17:34 +0000 (17:17 +0800)
shader/shader program objects to avoid memory access error.

src/mesa/main/context.c
src/mesa/shader/shader_api.c

index 087e18fb53e90679ae1f2615f5a5e8b12fd3012c..d94876e70bdeb3fef8a78b198df70d52deaebc9b 100644 (file)
@@ -622,6 +622,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().
@@ -721,6 +736,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
index df2f9dcec812d63ca1fa14d435ef7fc860abc8cf..01a237c525a231047b0f2d9e2936a0c82c806af4 100644 (file)
@@ -127,6 +127,8 @@ _mesa_free_shader_program_data(GLcontext *ctx,
    for (i = 0; i < shProg->NumShaders; i++) {
       _mesa_reference_shader(ctx, &shProg->Shaders[i], NULL);
    }
+   shProg->NumShaders = 0;
+
    if (shProg->Shaders) {
       _mesa_free(shProg->Shaders);
       shProg->Shaders = NULL;