fix: on error it was possible that leaveblock() is called after the function's already been deleted

This commit is contained in:
Wolfgang Bumiller 2013-01-15 14:28:15 +01:00
parent 150c6e21e7
commit 73afc98699

View file

@ -4010,6 +4010,14 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
} }
} }
func = ast_function_new(ast_ctx(var), var->name, var);
if (!func) {
parseerror(parser, "failed to allocate function for `%s`", var->name);
ast_block_delete(block);
goto enderr;
}
vec_push(parser->functions, func);
parser_enterblock(parser); parser_enterblock(parser);
for (parami = 0; parami < vec_size(var->expression.params); ++parami) { for (parami = 0; parami < vec_size(var->expression.params); ++parami) {
@ -4026,7 +4034,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
if (!create_vector_members(param, me)) { if (!create_vector_members(param, me)) {
ast_block_delete(block); ast_block_delete(block);
return false; goto enderrfn;
} }
for (e = 0; e < 3; ++e) { for (e = 0; e < 3; ++e) {
@ -4035,14 +4043,6 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
} }
} }
func = ast_function_new(ast_ctx(var), var->name, var);
if (!func) {
parseerror(parser, "failed to allocate function for `%s`", var->name);
ast_block_delete(block);
goto enderr;
}
vec_push(parser->functions, func);
if (var->argcounter) { if (var->argcounter) {
ast_value *argc = ast_value_new(ast_ctx(var), var->argcounter, TYPE_FLOAT); ast_value *argc = ast_value_new(ast_ctx(var), var->argcounter, TYPE_FLOAT);
parser_addlocal(parser, argc->name, (ast_expression*)argc); parser_addlocal(parser, argc->name, (ast_expression*)argc);
@ -4093,12 +4093,12 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
return retval; return retval;
enderrfn: enderrfn:
(void)!parser_leaveblock(parser);
vec_pop(parser->functions); vec_pop(parser->functions);
ast_function_delete(func); ast_function_delete(func);
var->constval.vfunc = NULL; var->constval.vfunc = NULL;
enderr: enderr:
(void)!parser_leaveblock(parser);
parser->function = old; parser->function = old;
return false; return false;
} }