threads / patch / 2937

patchcopy_fd: close ifd on error

Subject: [PATCH] copy_fd: close ifd on error

## tl;dr

2 messages between Dec 27, 2005 and Dec 27, 2005. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Sam Ravnborg· Dec 27, 2005, 08:19 UTC · lore
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
Show changes to copy.c +5 −2
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);
Junio C Hamano· Dec 27, 2005, 09:02 UTC · re: Sam Ravnborg · lore

Re: [PATCH] copy_fd: close ifd on error

Sam Ravnborg <sam@ravnborg.org> writes:
Show 7 quoted lines
> 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.

Thanks. I think the only place this matters is git-local-fetch which nobody uses these days where it can leak handful ifd. All other users immediately exit upon seeing failure return from the function.

Of course this would matter much when we do libification.

← back to recent threads