avoid double close of descriptors handed to run_command
authorJeff King <peff@peff.net>
Tue, 24 Jun 2014 09:45:46 +0000 (05:45 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Jun 2014 22:27:24 +0000 (15:27 -0700)
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>
builtin/replace.c
daemon.c
index 8507835d39664de640ccdd02df75743db19b4ec0..eb1d2ec5e53969b0feee3f1555b45b36a4030fab 100644 (file)
@@ -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);
 }
 
 /*
index eba12556848e975cd6f1a55ae25760823e90cdc8..a2701af2fc7341aa800fb1cb6dff97d14743844d 100644 (file)
--- 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)