Skip to contentSkip to conversation

copy_fd: close ifd on error

PATCH In review Sam Ravnborg 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 copy_fd: close ifd on error

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

---

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

Sam

copy.c +5 -2
index 7100eed..08a3d38 100644
@@ -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);
#1 lore raw
Quoted 7 lines · Sam Ravnborg

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

---

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.