]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'rs/apply-reject-fd-leakfix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 15 Apr 2024 21:11:42 +0000 (14:11 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Apr 2024 21:11:43 +0000 (14:11 -0700)
A file descriptor leak in an error codepath, used when "git apply
--reject" fails to create the *.rej file, has been corrected.

* rs/apply-reject-fd-leakfix:
  apply: don't leak fd on fdopen() error

apply.c

diff --git a/apply.c b/apply.c
index a5f716a7059fddbe3a78361ac0eed8a86dec39f1..34f20326a7f0ad2328b83af969d2c5419c2349eb 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -4665,8 +4665,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