Fix more bugs (mostly possible NULL pointer dereferences)
authorDale Weiler <killfieldengine@gmail.com>
Fri, 21 Jun 2013 23:26:49 +0000 (23:26 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Fri, 21 Jun 2013 23:26:49 +0000 (23:26 +0000)
ast.c
main.c
parser.c

diff --git a/ast.c b/ast.c
index 913e852190d309745822d4a66be50b1b0ade93c2..5c42a304e0fa1008eb72b1180e705133783adbe5 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1563,7 +1563,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
     return true;
 
 error: /* clean up */
     return true;
 
 error: /* clean up */
-    ir_value_delete(v);
+    if(v) ir_value_delete(v);
     return false;
 }
 
     return false;
 }
 
diff --git a/main.c b/main.c
index bcd91599e730bcc063c7b0f7f734325fef403057..ab9520ade17bfbb42119d05c398aacca87e8bdf0 100644 (file)
--- a/main.c
+++ b/main.c
@@ -791,7 +791,7 @@ cleanup:
     vec_free(ppems);
 
     if (!OPTS_OPTION_BOOL(OPTION_PP_ONLY))
     vec_free(ppems);
 
     if (!OPTS_OPTION_BOOL(OPTION_PP_ONLY))
-        parser_cleanup(parser);
+        if(parser) parser_cleanup(parser);
     if (opts_output_free)
         mem_d(OPTS_OPTION_STR(OPTION_OUTPUT));
     if (operators_free)
     if (opts_output_free)
         mem_d(OPTS_OPTION_STR(OPTION_OUTPUT));
     if (operators_free)
index 14f78035004e07c9689ec6e8b54fab451be5342c..6216997879e461e4c759cb17ec2959b9e362f5aa 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -3622,7 +3622,8 @@ static bool parse_goto(parser_t *parser, ast_expression **out)
         if (!(expression = parse_expression(parser, false, true)) ||
             !(*out = parse_goto_computed(parser, &expression))) {
             parseerror(parser, "invalid goto expression");
         if (!(expression = parse_expression(parser, false, true)) ||
             !(*out = parse_goto_computed(parser, &expression))) {
             parseerror(parser, "invalid goto expression");
-            ast_unref(expression);
+            if(expression)
+                ast_unref(expression);
             return false;
         }
 
             return false;
         }