diff options
| author | Bryan C. Mills <bcmills@google.com> | 2022-09-28 13:29:12 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-09-29 02:28:26 +0000 |
| commit | 4d6ca68a85e42c75683bc96aa540207566f54e26 (patch) | |
| tree | 603cece2f0ab25bbfdd5e690ecf5947dbd41b985 /src/os/exec/exec.go | |
| parent | 13d48bb6a1ad3787c10fbbe4265ad11672d90a37 (diff) | |
| download | go-4d6ca68a85e42c75683bc96aa540207566f54e26.tar.xz | |
os/exec: do not close pipes on a double-Start error
This fixes a bug introduced in CL 401834 in which calling Start twice
with pipes attached to a command would spuriously close those pipes
when returning the error from the second Start call.
For #50436.
Change-Id: I3563cc99c0a0987752190fef95da3e9927a76fda
Reviewed-on: https://go-review.googlesource.com/c/go/+/436095
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/os/exec/exec.go')
| -rw-r--r-- | src/os/exec/exec.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go index 67dd379b71..0dac34447f 100644 --- a/src/os/exec/exec.go +++ b/src/os/exec/exec.go @@ -490,6 +490,12 @@ func lookExtensions(path, dir string) (string, error) { // After a successful call to Start the Wait method must be called in // order to release associated system resources. func (c *Cmd) Start() error { + // Check for doubled Start calls before we defer failure cleanup. If the prior + // call to Start succeeded, we don't want to spuriously close its pipes. + if c.Process != nil { + return errors.New("exec: already started") + } + started := false defer func() { c.closeDescriptors(c.childIOFiles) @@ -519,9 +525,6 @@ func (c *Cmd) Start() error { } c.Path = lp } - if c.Process != nil { - return errors.New("exec: already started") - } if c.ctx != nil { select { case <-c.ctx.Done(): |
