copy.c::copy_fd() - do not leak file descriptor on error return.
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
5
copy.c
5
copy.c
@ -10,10 +10,13 @@ int copy_fd(int ifd, int ofd)
|
|||||||
if (!len)
|
if (!len)
|
||||||
break;
|
break;
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
|
int read_error;
|
||||||
if (errno == EAGAIN)
|
if (errno == EAGAIN)
|
||||||
continue;
|
continue;
|
||||||
|
read_error = errno;
|
||||||
|
close(ifd);
|
||||||
return error("copy-fd: read returned %s",
|
return error("copy-fd: read returned %s",
|
||||||
strerror(errno));
|
strerror(read_error));
|
||||||
}
|
}
|
||||||
while (1) {
|
while (1) {
|
||||||
int written = write(ofd, buf, len);
|
int written = write(ofd, buf, len);
|
||||||
|
Reference in New Issue
Block a user