@matheusbsbs / matheus-bagliano / commits / e6c64fc1e9
Fork 0

copy.c::copy_fd() - do not leak file descriptor on error return.

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 5, 2005 at 11:02 UTC e6c64fc1e9b3b9a5ea7101f8a2a499c9e2112da5
1 file changed +4 -1
copy.c
+4 -1
@@ -10,10 +10,13 @@ int copy_fd(int ifd, int ofd)
10 if (!len)
11 break;
12 if (len < 0) {
13 + int read_error;
14 if (errno == EAGAIN)
15 continue;
16 + read_error = errno;
17 + close(ifd);
18 return error("copy-fd: read returned %s",
16 - strerror(errno));
19 + strerror(read_error));
20 }
21 while (1) {
22 int written = write(ofd, buf, len);