apply: don't leak fd on fdopen() error
Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Apr 5, 2024 at 12:58 UTC
2b1f456adf8f0b574468661a65548106b317459b
1 file changed
+5
-2
apply.c
+5
-2
@@ -4644,8 +4644,11 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
4644
return error_errno(_("cannot open %s"), namebuf);
4645
}
4646
rej = fdopen(fd, "w");
4647
- if (!rej)
4648
- return error_errno(_("cannot open %s"), namebuf);
4647
+ if (!rej) {
4648
+ error_errno(_("cannot open %s"), namebuf);
4649
+ close(fd);
4650
+ return -1;
4651
+ }
4652
4653
/* Normal git tools never deal with .rej, so do not pretend
4654
* this is a git patch by saying --git or giving extended