summaryrefslogtreecommitdiffstats
path: root/src/mesa/shader/program_parse.y
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2009-07-27 12:21:26 -0700
committerIan Romanick <[email protected]>2009-07-27 12:21:26 -0700
commit94b45567047fd681666f261f1ad0164049f0491a (patch)
tree01f1a68b8ea73caa62a95c614fd0979257cf2db3 /src/mesa/shader/program_parse.y
parent946ea82bff530ac7aa8f5ebe56704fde62e14e86 (diff)
ARB prog: Clean up several memory leaks
As far as I am able to determine via code inspection and using Valgrind, that should be all of the leaks in the parser.
Diffstat (limited to 'src/mesa/shader/program_parse.y')
-rw-r--r--src/mesa/shader/program_parse.y35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/mesa/shader/program_parse.y b/src/mesa/shader/program_parse.y
index 8521a97b4f8..92e035997a3 100644
--- a/src/mesa/shader/program_parse.y
+++ b/src/mesa/shader/program_parse.y
@@ -1904,6 +1904,8 @@ declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
}
_mesa_symbol_table_add_symbol(state->st, 0, s->name, s);
+ s->next = state->sym;
+ state->sym = s;
}
return s;
@@ -2104,6 +2106,9 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
struct asm_instruction *inst;
unsigned i;
GLubyte *strz;
+ GLboolean result = GL_FALSE;
+ void *temp;
+ struct asm_symbol *sym;
state->ctx = ctx;
state->prog->Target = target;
@@ -2165,7 +2170,7 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
if (ctx->Program.ErrorPos != -1) {
- return GL_FALSE;
+ goto error;
}
if (! _mesa_layout_parameters(state)) {
@@ -2176,7 +2181,7 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
loc.position = len;
yyerror(& loc, state, "invalid PARAM usage");
- return GL_FALSE;
+ goto error;
}
@@ -2190,8 +2195,6 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
struct asm_instruction *const temp = inst->next;
state->prog->Instructions[i] = inst->Base;
- _mesa_free(inst);
-
inst = temp;
}
@@ -2215,5 +2218,27 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
state->prog->NumNativeAttributes = state->prog->NumAttributes;
state->prog->NumNativeAddressRegs = state->prog->NumAddressRegs;
- return GL_TRUE;
+ result = GL_TRUE;
+
+error:
+ for (inst = state->inst_head; inst != NULL; inst = temp) {
+ temp = inst->next;
+ _mesa_free(inst);
+ }
+
+ state->inst_head = NULL;
+ state->inst_tail = NULL;
+
+ for (sym = state->sym; sym != NULL; sym = temp) {
+ temp = sym->next;
+
+ _mesa_free((void *) sym->name);
+ _mesa_free(sym);
+ }
+ state->sym = NULL;
+
+ _mesa_symbol_table_dtor(state->st);
+ state->st = NULL;
+
+ return result;
}