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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jun 24, 2014 at 05:45 UTC
28bf9429ef2e1534be8d3a59ad236834be542b86
2 files changed
-3
builtin/replace.c
-2
@@ -207,8 +207,6 @@ static void export_object(const unsigned char *sha1, const char *filename)
207
208
if (run_command(&cmd))
209
die("cat-file reported failure");
210
-
211
- close(fd);
210
}
211
212
/*
daemon.c
-1
@@ -783,7 +783,6 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
783
logerror("unable to fork");
784
else
785
add_child(&cld, addr, addrlen);
786
- close(incoming);
786
}
787
788
static void child_handler(int signo)