Skip to content

Commit

Permalink
Make sure git_connect() always give two file descriptors.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jan 22, 2007
1 parent 026aa93 commit ec587fd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions builtin-archive.c
Expand Up @@ -74,6 +74,7 @@ static int run_remote_archiver(const char *remote, int argc,
/* Now, start reading from fd[0] and spit it out to stdout */
rv = recv_sideband("archive", fd[0], 1, 2);
close(fd[0]);
close(fd[1]);
rv |= finish_connect(pid);

return !!rv;
Expand Down
2 changes: 1 addition & 1 deletion connect.c
Expand Up @@ -529,7 +529,7 @@ static void git_tcp_connect(int fd[2], char *host)
int sockfd = git_tcp_connect_sock(host);

fd[0] = sockfd;
fd[1] = sockfd;
fd[1] = dup(sockfd);
}


Expand Down

0 comments on commit ec587fd

Please sign in to comment.