From b10a1b84e5d01b40f0f884bb535c35f7e20bfd7a Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 5 Aug 2022 21:31:54 +0300 Subject: [PATCH] fix: Fix close in `pty` and `ptytest` (#3392) --- pty/pty_other.go | 2 +- pty/ptytest/ptytest.go | 2 +- pty/start_other.go | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pty/pty_other.go b/pty/pty_other.go index 55f66b4d67..869d77fe0b 100644 --- a/pty/pty_other.go +++ b/pty/pty_other.go @@ -78,7 +78,7 @@ func (p *otherPty) Close() error { err := p.pty.Close() err2 := p.tty.Close() - if err != nil { + if err == nil { err = err2 } diff --git a/pty/ptytest/ptytest.go b/pty/ptytest/ptytest.go index 7abec9f181..4f67568c8f 100644 --- a/pty/ptytest/ptytest.go +++ b/pty/ptytest/ptytest.go @@ -62,7 +62,7 @@ func create(t *testing.T, ptty pty.PTY, name string) *PTY { _ = out.closeErr(err) }() t.Cleanup(func() { - _ = out.Close + _ = out.Close() _ = ptty.Close() <-copyDone }) diff --git a/pty/start_other.go b/pty/start_other.go index 40fe97a15a..4786f1a365 100644 --- a/pty/start_other.go +++ b/pty/start_other.go @@ -28,6 +28,7 @@ func startPty(cmd *exec.Cmd) (PTY, Process, error) { err = cmd.Start() if err != nil { _ = ptty.Close() + _ = tty.Close() if runtime.GOOS == "darwin" && strings.Contains(err.Error(), "bad file descriptor") { // MacOS has an obscure issue where the PTY occasionally closes // before it's used. It's unknown why this is, but creating a new