Skip to content

Commit ac8ce18

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 49800c9 commit ac8ce18

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

builtin/am.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,14 +762,18 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state,
762762
mail = mkpath("%s/%0*d", state->dir, state->prec, i + 1);
763763

764764
out = fopen(mail, "w");
765-
if (!out)
765+
if (!out) {
766+
if (in != stdin)
767+
fclose(in);
766768
return error_errno(_("could not open '%s' for writing"),
767769
mail);
770+
}
768771

769772
ret = fn(out, in, keep_cr);
770773

771774
fclose(out);
772-
fclose(in);
775+
if (in != stdin)
776+
fclose(in);
773777

774778
if (ret)
775779
return error(_("could not parse patch '%s'"), *paths);

0 commit comments

Comments
 (0)