From: Dale Weiler Date: Sat, 22 Jun 2013 01:14:13 +0000 (+0000) Subject: Fix some more bugs, and use dup2 because dup leaks on some implementations. X-Git-Tag: v0.3.0~87 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d39fb653aa3c5e807fb1b6b2a1aef8c3f608f409;p=xonotic%2Fgmqcc.git Fix some more bugs, and use dup2 because dup leaks on some implementations. --- diff --git a/parser.c b/parser.c index 6216997..49e965a 100644 --- a/parser.c +++ b/parser.c @@ -2056,7 +2056,7 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels) correct = correct_str(&corr, parser->correct_variables[i], parser_tokval(parser)); if (strcmp(correct, parser_tokval(parser))) { break; - } else if (correct) { + } else { mem_d(correct); correct = NULL; } @@ -2514,7 +2514,8 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond, } unary = (ast_unary*)cond; - while (ast_istype(cond, ast_unary) && unary->op == INSTR_NOT_F) + /* ast_istype dereferences cond, should test here for safety */ + while (cond && ast_istype(cond, ast_unary) && unary->op == INSTR_NOT_F) { cond = unary->operand; unary->operand = NULL; diff --git a/test.c b/test.c index 5f7eac7..cdb9041 100644 --- a/test.c +++ b/test.c @@ -104,6 +104,7 @@ static FILE ** task_popen(const char *command, const char *mode) { data->pipes [0] = inhandle [1]; data->pipes [1] = outhandle[0]; data->pipes [2] = errhandle[0]; + data->handles[0] = fdopen(inhandle [1], "w"); data->handles[1] = fdopen(outhandle[0], mode); data->handles[2] = fdopen(errhandle[0], mode); @@ -119,9 +120,9 @@ static FILE ** task_popen(const char *command, const char *mode) { close(errhandle[0]); /* see piping documentation for this sillyness :P */ - close(0); (void)!dup(inhandle [0]); - close(1); (void)!dup(outhandle[1]); - close(2); (void)!dup(errhandle[1]); + dup2(inhandle [0], 0); + dup2(outhandle[1], 1); + dup2(errhandle[1], 2); execvp(*argv, argv); exit(EXIT_FAILURE); @@ -135,8 +136,7 @@ task_popen_error_2: close(outhandle[0]), close(outhandle[1]); task_popen_error_1: close(inhandle [0]), close(inhandle [1]); task_popen_error_0: - if (argv) - vec_free(argv); + vec_free(argv); return NULL; } @@ -474,8 +474,7 @@ static bool task_template_parse(const char *file, task_template_t *tmpl, FILE *f return true; failure: - if (back) - mem_d (back); + mem_d (back); return false; }