gallium: fix a few mem leaks when deleting programs
authorBrian <brian.paul@tungstengraphics.com>
Sat, 22 Mar 2008 15:12:52 +0000 (09:12 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Sat, 22 Mar 2008 15:12:52 +0000 (09:12 -0600)
src/mesa/state_tracker/st_cb_program.c

index 0a62e20e0c6262f1ca285d2243ab062f3ceac457..7cf352d710b68d371a249eab1ebe8eea1ad96351 100644 (file)
@@ -126,12 +126,17 @@ static void st_delete_program( GLcontext *ctx,
                               struct gl_program *prog )
 {
    struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
 
    switch( prog->Target ) {
    case GL_VERTEX_PROGRAM_ARB:
       {
          struct st_vertex_program *stvp = (struct st_vertex_program *) prog;
          st_remove_vertex_program(st, stvp);
+         if (stvp->driver_shader) {
+            pipe->delete_vs_state(pipe, stvp->driver_shader);
+            stvp->driver_shader = NULL;
+         }
       }
       break;
    case GL_FRAGMENT_PROGRAM_ARB:
@@ -139,6 +144,13 @@ static void st_delete_program( GLcontext *ctx,
          struct st_fragment_program *stfp
             = (struct st_fragment_program *) prog;
          st_remove_fragment_program(st, stfp);
+         if (stfp->driver_shader) {
+            pipe->delete_fs_state(pipe, stfp->driver_shader);
+            stfp->driver_shader = NULL;
+         }
+
+         assert(!stfp->vertex_programs);
+
       }
       break;
    default:
@@ -162,19 +174,17 @@ static void st_program_string_notify( GLcontext *ctx,
                                      struct gl_program *prog )
 {
    struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
 
    if (target == GL_FRAGMENT_PROGRAM_ARB) {
       struct st_fragment_program *stfp = (struct st_fragment_program *) prog;
 
       stfp->serialNo++;
 
-#if 0
-      if (stfp->cso) {
-         /* free the TGSI code */
-         // cso_delete(stfp->vs);
-         stfp->cso = NULL;
+      if (stfp->driver_shader) {
+         pipe->delete_fs_state(pipe, stfp->driver_shader);
+         stfp->driver_shader = NULL;
       }
-#endif
 
       stfp->param_state = stfp->Base.Base.Parameters->StateFlags;
 
@@ -191,14 +201,11 @@ static void st_program_string_notify( GLcontext *ctx,
 
       stvp->serialNo++;
 
-#if 0
-      if (stvp->cso) {
-         /* free the CSO data */
-         st->pipe->delete_vs_state(st->pipe, stvp->cso->data);
-         FREE((void *) stvp->cso);
-         stvp->cso = NULL;
+      if (stvp->driver_shader) {
+         pipe->delete_vs_state(pipe, stvp->driver_shader);
+         stvp->driver_shader = NULL;
       }
-#endif
+
       if (stvp->draw_shader) {
          draw_delete_vertex_shader(st->draw, stvp->draw_shader);
          stvp->draw_shader = NULL;