[PATCH] copy_fd: close ifd on error

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <git@...>
Date: Tuesday, December 27, 2005 - 4:19 am

In copy_fd when write fails we ought to close input file descriptor.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---

Found while looking at the source for inspiration for something else.
I did not see any error related to this.

	Sam

diff --git a/copy.c b/copy.c
index 7100eed..08a3d38 100644
--- 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);
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] copy_fd: close ifd on error, Sam Ravnborg, (Tue Dec 27, 4:19 am)
Re: [PATCH] copy_fd: close ifd on error, Junio C Hamano, (Tue Dec 27, 5:02 am)