From: Jeff King Date: Tue, 24 Jun 2014 09:45:46 +0000 (-0400) Subject: avoid double close of descriptors handed to run_command X-Git-Tag: v2.1.0-rc0~43^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28bf9429ef2e1534be8d3a59ad236834be542b86;p=git avoid double close of descriptors handed to run_command When a file descriptor is given to run_command via the "in", "out", or "err" parameters, run_command takes ownership. The descriptor will be closed in the parent process whether the process is spawned successfully or not, and closing it again is wrong. In practice this has not caused problems, because we usually close() right after start_command returns, meaning no other code has opened a descriptor in the meantime. So we just get EBADF and ignore it (rather than accidentally closing somebody else's descriptor!). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/builtin/replace.c b/builtin/replace.c index 8507835d39..eb1d2ec5e5 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -207,8 +207,6 @@ static void export_object(const unsigned char *sha1, const char *filename) if (run_command(&cmd)) die("cat-file reported failure"); - - close(fd); } /* diff --git a/daemon.c b/daemon.c index eba1255684..a2701af2fc 100644 --- a/daemon.c +++ b/daemon.c @@ -783,7 +783,6 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen) logerror("unable to fork"); else add_child(&cld, addr, addrlen); - close(incoming); } static void child_handler(int signo)