Mesa (master): ir_to_mesa: Let check_resources halt compilation

Ian Romanick idr at kemper.freedesktop.org
Fri Oct 28 13:29:31 PDT 2011


Module: Mesa
Branch: master
Commit: 276000472abbc34d86fcb628bc3a1990e9581af3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=276000472abbc34d86fcb628bc3a1990e9581af3

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Oct 11 16:27:41 2011 -0700

ir_to_mesa: Let check_resources halt compilation

Previously check_resources could fail, but we'd still try to optimize
the shader, do device-specific code generation, etc.  In some cases,
this could explode (especially in the device-specific code
generation).  I haven't found that I could trigger this with the
current code.  When too many samplers were used with the new uniform
handling code, I observed several crashes deep down in the driver.

NOTE: This is candidate for the 7.11 branch.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=41609
Cc: Eric Anholt <eric at anholt.net>
Reviewed-and-tested-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/mesa/program/ir_to_mesa.cpp |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 93563bd..3bf2cc7 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2546,7 +2546,7 @@ count_resources(struct gl_program *prog)
  *
  * XXX more checks are needed...
  */
-static void
+static bool
 check_resources(const struct gl_context *ctx,
                 struct gl_shader_program *shader_program,
                 struct gl_program *prog)
@@ -2586,6 +2586,8 @@ check_resources(const struct gl_context *ctx,
    default:
       _mesa_problem(ctx, "unexpected program type in check_resources()");
    }
+
+   return shader_program->LinkStatus;
 }
 
 class add_uniform_to_shader : public uniform_field_visitor {
@@ -3168,9 +3170,7 @@ get_mesa_program(struct gl_context *ctx,
    }
 
    if (!shader_program->LinkStatus) {
-      free(mesa_instructions);
-      _mesa_reference_program(ctx, &shader->Program, NULL);
-      return NULL;
+      goto fail_exit;
    }
 
    set_branchtargets(&v, mesa_instructions, num_instructions);
@@ -3191,10 +3191,16 @@ get_mesa_program(struct gl_context *ctx,
    prog->Instructions = mesa_instructions;
    prog->NumInstructions = num_instructions;
 
+   /* Setting this to NULL prevents a possible double free in the fail_exit
+    * path (far below).
+    */
+   mesa_instructions = NULL;
+
    do_set_program_inouts(shader->ir, prog, shader->Type == GL_FRAGMENT_SHADER);
    count_resources(prog);
 
-   check_resources(ctx, shader_program, prog);
+   if (!check_resources(ctx, shader_program, prog))
+      goto fail_exit;
 
    _mesa_reference_program(ctx, &shader->Program, prog);
 
@@ -3203,6 +3209,11 @@ get_mesa_program(struct gl_context *ctx,
    }
 
    return prog;
+
+fail_exit:
+   free(mesa_instructions);
+   _mesa_reference_program(ctx, &shader->Program, NULL);
+   return NULL;
 }
 
 extern "C" {
@@ -3301,7 +3312,7 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       _mesa_reference_program(ctx, &linked_prog, NULL);
    }
 
-   return GL_TRUE;
+   return prog->LinkStatus;
 }
 
 



More information about the mesa-commit mailing list