git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] copy_fd: close ifd on error
@ 2005-12-27  8:19 Sam Ravnborg
  2005-12-27  9:02 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Sam Ravnborg @ 2005-12-27  8:19 UTC (permalink / raw)
  To: git

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);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-12-27  9:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-27  8:19 [PATCH] copy_fd: close ifd on error Sam Ravnborg
2005-12-27  9:02 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).