Fix possible NULL pointer dereference
authorDale Weiler <killfieldengine@gmail.com>
Fri, 21 Jun 2013 23:21:12 +0000 (23:21 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Fri, 21 Jun 2013 23:21:12 +0000 (23:21 +0000)
ast.c

diff --git a/ast.c b/ast.c
index f814847714d5d158ed8ebd15a5bd87a3d1cfd1dc..913e852190d309745822d4a66be50b1b0ade93c2 100644 (file)
--- 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);
 
 {
     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);
         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;
     }
 
     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;
     self->return_value     = NULL;
 
     return self;
+    
+cleanup:
+    mem_d(self);
+    return NULL;
 }
 
 void ast_function_delete(ast_function *self)
 }
 
 void ast_function_delete(ast_function *self)