{"thread":{"id":"2937","subject":"[PATCH] copy_fd: close ifd on error","startedAt":"2005-12-27T08:19:05Z","lastAt":"2005-12-27T09:02:41Z","messageCount":2,"participants":["Sam Ravnborg","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"14060","messageId":"20051227081905.GA9946@mars.ravnborg.org","threadId":"2937","inReplyTo":null,"subject":"[PATCH] copy_fd: close ifd on error","fromName":"Sam Ravnborg","fromEmail":"sam@ravnborg.org","sentAt":"2005-12-27T08:19:05Z","receivedAt":"2005-12-27T08:19:05Z","isPatch":true,"sender":{"key":"sam@ravnborg.org","avatar":"https://gravatar.com/avatar/168a912606ed0742d840bb365e3cc21db390c36531a58341dc7a069cc1f15f62?d=mp&s=160"},"body":"In copy_fd when write fails we ought to close input file descriptor.\n\nSigned-off-by: Sam Ravnborg <sam@ravnborg.org>\n---\n\nFound while looking at the source for inspiration for something else.\nI did not see any error related to this.\n\n\tSam\n\ndiff --git a/copy.c b/copy.c\nindex 7100eed..08a3d38 100644\n--- a/copy.c\n+++ b/copy.c\n@@ -22,11 +22,14 @@ int copy_fd(int ifd, int ofd)\n \t\t\t\tbuf += written;\n \t\t\t\tlen -= written;\n \t\t\t}\n-\t\t\telse if (!written)\n+\t\t\telse if (!written) {\n+\t\t\t\tclose(ifd);\n \t\t\t\treturn error(\"copy-fd: write returned 0\");\n-\t\t\telse\n+\t\t\t} else {\n+\t\t\t\tclose(ifd);\n \t\t\t\treturn error(\"copy-fd: write returned %s\",\n \t\t\t\t\t     strerror(errno));\n+\t\t\t}\n \t\t}\n \t}\n \tclose(ifd);\n"},{"id":"14061","messageId":"7vpsnic3pq.fsf@assigned-by-dhcp.cox.net","threadId":"2937","inReplyTo":"20051227081905.GA9946@mars.ravnborg.org","subject":"Re: [PATCH] copy_fd: close ifd on error","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-27T09:02:41Z","receivedAt":"2005-12-27T09:02:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sam Ravnborg <sam@ravnborg.org> writes:\n\n> In copy_fd when write fails we ought to close input file descriptor.\n>\n> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>\n> ---\n>\n> Found while looking at the source for inspiration for something else.\n> I did not see any error related to this.\n\nThanks.  I think the only place this matters is git-local-fetch\nwhich nobody uses these days where it can leak handful ifd.\nAll other users immediately exit upon seeing failure return from\nthe function.\n\nOf course this would matter much when we do libification.\n"}]}