mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-12-18 00:11:06 +00:00
fix: on error it was possible that leaveblock() is called after the function's already been deleted
This commit is contained in:
parent
150c6e21e7
commit
73afc98699
1 changed files with 10 additions and 10 deletions
20
parser.c
20
parser.c
|
@ -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);
|
||||
|
||||
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)) {
|
||||
ast_block_delete(block);
|
||||
return false;
|
||||
goto enderrfn;
|
||||
}
|
||||
|
||||
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) {
|
||||
ast_value *argc = ast_value_new(ast_ctx(var), var->argcounter, TYPE_FLOAT);
|
||||
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;
|
||||
|
||||
enderrfn:
|
||||
(void)!parser_leaveblock(parser);
|
||||
vec_pop(parser->functions);
|
||||
ast_function_delete(func);
|
||||
var->constval.vfunc = NULL;
|
||||
|
||||
enderr:
|
||||
(void)!parser_leaveblock(parser);
|
||||
parser->function = old;
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue