Skip to content

Commit

Permalink
avoid double close of descriptors handed to run_command
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 25, 2014
1 parent 3cc9d87 commit 28bf942
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 3 deletions.
2 changes: 0 additions & 2 deletions builtin/replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down
1 change: 0 additions & 1 deletion daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 28bf942

Please sign in to comment.