Fix some more bugs, and use dup2 because dup leaks on some implementations.

This commit is contained in:
Dale Weiler 2013-06-22 01:14:13 +00:00
parent e08f00bfcd
commit d39fb653aa
2 changed files with 9 additions and 9 deletions

View file

@ -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;

13
test.c
View file

@ -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;
}