Skip to content

Commit 28bf942

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3cc9d87 commit 28bf942

File tree

2 files changed

+0
-3
lines changed

2 files changed

+0
-3
lines changed

builtin/replace.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ static void export_object(const unsigned char *sha1, const char *filename)
207207

208208
if (run_command(&cmd))
209209
die("cat-file reported failure");
210-
211-
close(fd);
212210
}
213211

214212
/*

daemon.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,6 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
783783
logerror("unable to fork");
784784
else
785785
add_child(&cld, addr, addrlen);
786-
close(incoming);
787786
}
788787

789788
static void child_handler(int signo)

0 commit comments

Comments
 (0)