From 2b1f456adf8f0b574468661a65548106b317459b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Fri, 5 Apr 2024 12:58:16 +0200 Subject: [PATCH] apply: don't leak fd on fdopen() error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- apply.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apply.c b/apply.c index 7608e3301c..9a131a5ecd 100644 --- a/apply.c +++ b/apply.c @@ -4644,8 +4644,11 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch) return error_errno(_("cannot open %s"), namebuf); } rej = fdopen(fd, "w"); - if (!rej) - return error_errno(_("cannot open %s"), namebuf); + if (!rej) { + error_errno(_("cannot open %s"), namebuf); + close(fd); + return -1; + } /* Normal git tools never deal with .rej, so do not pretend * this is a git patch by saying --git or giving extended