Code

copy_fd: close ifd on error
authorSam Ravnborg <sam@ravnborg.org>
Tue, 27 Dec 2005 08:19:05 +0000 (09:19 +0100)
committerJunio C Hamano <junkio@cox.net>
Tue, 27 Dec 2005 18:49:25 +0000 (10:49 -0800)
In copy_fd when write fails we ought to close input file descriptor.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
copy.c

diff --git a/copy.c b/copy.c
index 7100eedbc3277b9b0997311459d054ba06950b61..08a3d388a4c312fca18558b2b8e5dcf027c7afaf 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -22,11 +22,14 @@ int copy_fd(int ifd, int ofd)
                                buf += written;
                                len -= written;
                        }
-                       else if (!written)
+                       else if (!written) {
+                               close(ifd);
                                return error("copy-fd: write returned 0");
-                       else
+                       } else {
+                               close(ifd);
                                return error("copy-fd: write returned %s",
                                             strerror(errno));
+                       }
                }
        }
        close(ifd);