@matheusbsbs / matheus-bagliano / commits / 08337a97a2
Fork 0

copy_fd: close ifd on error

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>

Sam Ravnborg committed Dec 27, 2005 at 09:19 UTC 08337a97a2756cd89ab611444f37d67250d3c05b
1 file changed +5 -2
copy.c
+5 -2
@@ -22,11 +22,14 @@ int copy_fd(int ifd, int ofd)
22 buf += written;
23 len -= written;
24 }
25 - else if (!written)
25 + else if (!written) {
26 + close(ifd);
27 return error("copy-fd: write returned 0");
27 - else
28 + } else {
29 + close(ifd);
30 return error("copy-fd: write returned %s",
31 strerror(errno));
32 + }
33 }
34 }
35 close(ifd);