From 4e38f139f92b8b3729f82c37f0904c2b77d3eb58 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 21 Oct 2017 13:10:36 -0400 Subject: Report errors that occur when closing files Otherwise we miss write errors that occur when flushing the cache. --- parse.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'parse.c') diff --git a/parse.c b/parse.c index 46c860c..b4b7ddc 100644 --- a/parse.c +++ b/parse.c @@ -80,11 +80,14 @@ struct expr expr_false = { /** * Free an expression. */ -void free_expr(struct expr *expr) { +int free_expr(struct expr *expr) { + int ret = 0; + if (expr && expr != &expr_true && expr != &expr_false) { if (expr->cfile && expr->cfile->close) { if (cfclose(expr->cfile) != 0) { perror("cfclose()"); + ret = -1; } } @@ -96,10 +99,17 @@ void free_expr(struct expr *expr) { free_bfs_printf(expr->printf); free_bfs_exec(expr->execbuf); - free_expr(expr->lhs); - free_expr(expr->rhs); + if (free_expr(expr->lhs) != 0) { + ret = -1; + } + if (free_expr(expr->rhs) != 0) { + ret = -1; + } + free(expr); } + + return ret; } struct expr *new_expr(eval_fn *eval, size_t argc, char **argv) { @@ -224,14 +234,25 @@ void dump_expr(CFILE *cfile, const struct expr *expr, bool verbose) { /** * Free the parsed command line. */ -void free_cmdline(struct cmdline *cmdline) { +int free_cmdline(struct cmdline *cmdline) { + int ret = 0; + if (cmdline) { - free_expr(cmdline->expr); + if (free_expr(cmdline->expr) != 0) { + ret = -1; + } free_bfs_mtab(cmdline->mtab); - cfclose(cmdline->cerr); - cfclose(cmdline->cout); + if (cfclose(cmdline->cerr) != 0) { + perror("cfclose()"); + ret = -1; + } + if (cfclose(cmdline->cout) != 0) { + perror("cfclose()"); + ret = -1; + } + free_colors(cmdline->colors); struct root *root = cmdline->roots; @@ -244,6 +265,8 @@ void free_cmdline(struct cmdline *cmdline) { free(cmdline->argv); free(cmdline); } + + return ret; } /** -- cgit v1.2.3