git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] copy_fd: close ifd on error

From
Sam Ravnborg <sam@ravnborg.org>
Date
Dec 27, 2005, 08:19 UTC
Message-ID
<20051227081905.GA9946@mars.ravnborg.org>
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);
Next: Junio C Hamano
Message 1 of 2 in “copy_fd: close ifd on error”
  1. copy_fd: close ifd on errorSam Ravnborg, Dec 27, 2005
  2. Junio C HamanoDec 27, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.