summaryrefslogtreecommitdiff
path: root/builtin/am.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-04-16 16:55:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-04-17 04:27:39 (GMT)
commitac8ce18d89acccaa7a66900adff75d4aeb6ec80b (patch)
tree258de46a4f032e808903a5d9c359f57514de1a38 /builtin/am.c
parent49800c940790cc7465d1b03e08d472ffd8684808 (diff)
downloadgit-ac8ce18d89acccaa7a66900adff75d4aeb6ec80b.zip
git-ac8ce18d89acccaa7a66900adff75d4aeb6ec80b.tar.gz
git-ac8ce18d89acccaa7a66900adff75d4aeb6ec80b.tar.bz2
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 <l.s.r@web.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/am.c')
-rw-r--r--builtin/am.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 31fb605..1729600 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);