From: René Scharfe Date: Sun, 16 Apr 2017 16:55:30 +0000 (+0200) Subject: am: close stream on error, but not stdin X-Git-Tag: v2.13.0-rc1~20^2~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ac8ce18d89acccaa7a66900adff75d4aeb6ec80b?hp=--cc am: close stream on error, but not stdin Avoid closing stdin, but do close an actual input file on error exit. Found with Cppcheck. Signed-off-by: Rene Scharfe Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- ac8ce18d89acccaa7a66900adff75d4aeb6ec80b diff --git a/builtin/am.c b/builtin/am.c index 31fb60578f..172960094c 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -762,14 +762,18 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state, mail = mkpath("%s/%0*d", state->dir, state->prec, i + 1); out = fopen(mail, "w"); - if (!out) + if (!out) { + if (in != stdin) + fclose(in); return error_errno(_("could not open '%s' for writing"), mail); + } ret = fn(out, in, keep_cr); fclose(out); - fclose(in); + if (in != stdin) + fclose(in); if (ret) return error(_("could not parse patch '%s'"), *paths);