]> git.ipfire.org Git - thirdparty/git.git/commitdiff
apply: don't leak fd on fdopen() error
authorRené Scharfe <l.s.r@web.de>
Fri, 5 Apr 2024 10:58:16 +0000 (12:58 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Apr 2024 17:09:26 +0000 (10:09 -0700)
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
apply.c

diff --git a/apply.c b/apply.c
index 7608e3301ca0727dcfec0a579ed46390afa41ab0..9a131a5ecd97d267e27b41beee34c65e28d5e1c7 100644 (file)
--- 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