Re: [PATCH 04/13] run-command: avoid close(-1) in start_command() error paths
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Jul 1, 2026, 07:56 UTC
- Message-ID
- <akTIK6j9UY4U4x80@pks.im>
- In-Reply-To
- <d7bcdda31276b5a17f11c307deb0f99ae1dc2861.1782889472.git.gitgitgadget@gmail.com>
On Wed, Jul 01, 2026 at 07:04:22AM +0000, Johannes Schindelin via GitGitGadget wrote:
Show 27 quoted lines
> diff --git a/run-command.c b/run-command.c > index e70a8a387b..ce84db8782 100644 > --- a/run-command.c > +++ b/run-command.c > @@ -706,7 +706,7 @@ int start_command(struct child_process *cmd) > failed_errno = errno; > if (need_in) > close_pair(fdin); > - else if (cmd->in) > + else if (cmd->in > 0) > close(cmd->in); > str = "standard output"; > goto fail_pipe; > @@ -720,11 +720,11 @@ int start_command(struct child_process *cmd) > failed_errno = errno; > if (need_in) > close_pair(fdin); > - else if (cmd->in) > + else if (cmd->in > 0) > close(cmd->in); > if (need_out) > close_pair(fdout); > - else if (cmd->out) > + else if (cmd->out > 0) > close(cmd->out); > str = "standard error"; > fail_pipe:
Right. There's a fourth site that does `close(cmd->out)`, but that site already guards with `if (cmd->out > 0)`.
Patrick