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.
This commit is contained in:
@@ -4700,6 +4700,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);
|
_mesa_symbol_table_add_symbol(state->st, 0, s->name, s);
|
||||||
|
s->next = state->sym;
|
||||||
|
state->sym = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
@@ -4900,6 +4902,9 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
|
|||||||
struct asm_instruction *inst;
|
struct asm_instruction *inst;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
GLubyte *strz;
|
GLubyte *strz;
|
||||||
|
GLboolean result = GL_FALSE;
|
||||||
|
void *temp;
|
||||||
|
struct asm_symbol *sym;
|
||||||
|
|
||||||
state->ctx = ctx;
|
state->ctx = ctx;
|
||||||
state->prog->Target = target;
|
state->prog->Target = target;
|
||||||
@@ -4961,7 +4966,7 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
|
|||||||
|
|
||||||
|
|
||||||
if (ctx->Program.ErrorPos != -1) {
|
if (ctx->Program.ErrorPos != -1) {
|
||||||
return GL_FALSE;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! _mesa_layout_parameters(state)) {
|
if (! _mesa_layout_parameters(state)) {
|
||||||
@@ -4972,7 +4977,7 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
|
|||||||
loc.position = len;
|
loc.position = len;
|
||||||
|
|
||||||
yyerror(& loc, state, "invalid PARAM usage");
|
yyerror(& loc, state, "invalid PARAM usage");
|
||||||
return GL_FALSE;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -4986,8 +4991,6 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
|
|||||||
struct asm_instruction *const temp = inst->next;
|
struct asm_instruction *const temp = inst->next;
|
||||||
|
|
||||||
state->prog->Instructions[i] = inst->Base;
|
state->prog->Instructions[i] = inst->Base;
|
||||||
_mesa_free(inst);
|
|
||||||
|
|
||||||
inst = temp;
|
inst = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5011,6 +5014,28 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
|
|||||||
state->prog->NumNativeAttributes = state->prog->NumAttributes;
|
state->prog->NumNativeAttributes = state->prog->NumAttributes;
|
||||||
state->prog->NumNativeAddressRegs = state->prog->NumAddressRegs;
|
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(sym->name);
|
||||||
|
_mesa_free(sym);
|
||||||
|
}
|
||||||
|
state->sym = NULL;
|
||||||
|
|
||||||
|
_mesa_symbol_table_dtor(state->st);
|
||||||
|
state->st = NULL;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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);
|
_mesa_symbol_table_add_symbol(state->st, 0, s->name, s);
|
||||||
|
s->next = state->sym;
|
||||||
|
state->sym = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
@@ -2104,6 +2106,9 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
|
|||||||
struct asm_instruction *inst;
|
struct asm_instruction *inst;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
GLubyte *strz;
|
GLubyte *strz;
|
||||||
|
GLboolean result = GL_FALSE;
|
||||||
|
void *temp;
|
||||||
|
struct asm_symbol *sym;
|
||||||
|
|
||||||
state->ctx = ctx;
|
state->ctx = ctx;
|
||||||
state->prog->Target = target;
|
state->prog->Target = target;
|
||||||
@@ -2165,7 +2170,7 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
|
|||||||
|
|
||||||
|
|
||||||
if (ctx->Program.ErrorPos != -1) {
|
if (ctx->Program.ErrorPos != -1) {
|
||||||
return GL_FALSE;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! _mesa_layout_parameters(state)) {
|
if (! _mesa_layout_parameters(state)) {
|
||||||
@@ -2176,7 +2181,7 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
|
|||||||
loc.position = len;
|
loc.position = len;
|
||||||
|
|
||||||
yyerror(& loc, state, "invalid PARAM usage");
|
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;
|
struct asm_instruction *const temp = inst->next;
|
||||||
|
|
||||||
state->prog->Instructions[i] = inst->Base;
|
state->prog->Instructions[i] = inst->Base;
|
||||||
_mesa_free(inst);
|
|
||||||
|
|
||||||
inst = temp;
|
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->NumNativeAttributes = state->prog->NumAttributes;
|
||||||
state->prog->NumNativeAddressRegs = state->prog->NumAddressRegs;
|
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;
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,7 @@ enum asm_type {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct asm_symbol {
|
struct asm_symbol {
|
||||||
|
struct asm_symbol *next; /**< List linkage for freeing. */
|
||||||
const char *name;
|
const char *name;
|
||||||
enum asm_type type;
|
enum asm_type type;
|
||||||
unsigned attrib_binding;
|
unsigned attrib_binding;
|
||||||
@@ -134,6 +135,14 @@ struct asm_parser_state {
|
|||||||
|
|
||||||
struct _mesa_symbol_table *st;
|
struct _mesa_symbol_table *st;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Linked list of symbols
|
||||||
|
*
|
||||||
|
* This list is \b only used when cleaning up compiler state and freeing
|
||||||
|
* memory.
|
||||||
|
*/
|
||||||
|
struct asm_symbol *sym;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* State for the lexer.
|
* State for the lexer.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user