From 996d998ebbede68ff624ace1b2b5c291cb361280 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Fri, 21 Jun 2013 23:21:12 +0000 Subject: [PATCH] Fix possible NULL pointer dereference --- ast.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ast.c b/ast.c index f814847..913e852 100644 --- a/ast.c +++ b/ast.c @@ -1152,16 +1152,15 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype) { ast_instantiate(ast_function, ctx, ast_function_delete); - if (!vtype || - vtype->hasvalue || - vtype->expression.vtype != TYPE_FUNCTION) - { + if (!vtype) { + compile_error(ast_ctx(self), "internal error: ast_function_new condition 0"); + goto cleanup; + } else if (vtype->hasvalue || vtype->expression.vtype != TYPE_FUNCTION) { compile_error(ast_ctx(self), "internal error: ast_function_new condition %i %i type=%i (probably 2 bodies?)", (int)!vtype, (int)vtype->hasvalue, vtype->expression.vtype); - mem_d(self); - return NULL; + goto cleanup; } self->vtype = vtype; @@ -1186,6 +1185,10 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype) self->return_value = NULL; return self; + +cleanup: + mem_d(self); + return NULL; } void ast_function_delete(ast_function *self) -- 2.39.2