wt-status: use capture_command

When we spawn "git submodule status" to read its output, we use run_command() followed by strbuf_read() read from the pipe. This can deadlock if the subprocess output is larger than the system pipe buffer. Furthermore, if start_command() fails, we'll try to read from a bogus descriptor (probably "-1" or a descriptor we just closed, but it is a bad idea for us to make assumptions about how start_command implements its error handling). And if start_command succeeds, we leak the file descriptor for the pipe to the child. All of these can be solved by using the capture_command helper. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 22, 2015 at 23:53 UTC 5c950e9bf098b17bb37e06f7c9f50d24e9d2904f
1 file changed +1 -4
wt-status.c
+1 -4
@@ -744,11 +744,8 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
744
745 sm_summary.git_cmd = 1;
746 sm_summary.no_stdin = 1;
747 - sm_summary.out = -1;
747
749 - run_command(&sm_summary);
750 -
751 - strbuf_read(&cmd_stdout, sm_summary.out, 1024);
748 + capture_command(&sm_summary, &cmd_stdout, 1024);
749
750 /* prepend header, only if there's an actual output */
751 if (cmd_stdout.len) {