@matheusbsbs / matheus-bagliano / commits / ec587fde0a
Fork 0

Make sure git_connect() always give two file descriptors.

Earlier, git_connect() returned the same fd twice or two separate fds, depending on the way the connection was made (when we are talking to the other end over a single socket, we used the same fd twice, and when our end is connected to a pipepair we used two). This forced callers who do close() and dup() to really care which was which, and most of the existing callers got this wrong, although without much visible ill effect. Many were closing the same fd twice when we are talking over a single socket, and one was leaking a fd. This fixes it to uniformly use two separate fds, so if somebody wants to close only reader side can just do close() on it without worrying about it accidentally also closing the writer side or vice versa. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 21, 2007 at 17:10 UTC ec587fde0a76780931c7ac32474c8c000aa45134
2 files changed +2 -1
builtin-archive.c
+1
@@ -74,6 +74,7 @@ static int run_remote_archiver(const char *remote, int argc,
74 /* Now, start reading from fd[0] and spit it out to stdout */
75 rv = recv_sideband("archive", fd[0], 1, 2);
76 close(fd[0]);
77 + close(fd[1]);
78 rv |= finish_connect(pid);
79
80 return !!rv;
connect.c
+1 -1
@@ -529,7 +529,7 @@ static void git_tcp_connect(int fd[2], char *host)
529 int sockfd = git_tcp_connect_sock(host);
530
531 fd[0] = sockfd;
532 - fd[1] = sockfd;
532 + fd[1] = dup(sockfd);
533 }
534
535