diff options
| author | Tobias Klauser <tklauser@distanz.ch> | 2021-04-13 11:01:13 +0200 |
|---|---|---|
| committer | Tobias Klauser <tobias.klauser@gmail.com> | 2021-04-14 05:49:15 +0000 |
| commit | 58fdac04e4534e53fd9ca7df0455efb4f1ddb82b (patch) | |
| tree | 53511cf11e1d4b4cce85d72ae8b2ff32ac978835 /src/syscall | |
| parent | 6d8ba77896d05720e1cb1728c27db60926e672b5 (diff) | |
| download | go-58fdac04e4534e53fd9ca7df0455efb4f1ddb82b.tar.xz | |
syscall: don't defer close raw Socketpair fds in tests
The raw fds are successively wrapped using os.NewFile and will be closed
by (*os.File).Close. Avoids a double close, in the worst case closing an
unrelated fd.
Change-Id: I86aabe5ed865eff43d264ddae1fb07c935868e97
Reviewed-on: https://go-review.googlesource.com/c/go/+/309353
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/syscall')
| -rw-r--r-- | src/syscall/creds_test.go | 9 | ||||
| -rw-r--r-- | src/syscall/syscall_unix_test.go | 2 |
2 files changed, 5 insertions, 6 deletions
diff --git a/src/syscall/creds_test.go b/src/syscall/creds_test.go index 463033d558..736b497bc4 100644 --- a/src/syscall/creds_test.go +++ b/src/syscall/creds_test.go @@ -38,16 +38,19 @@ func TestSCMCredentials(t *testing.T) { if err != nil { t.Fatalf("Socketpair: %v", err) } - defer syscall.Close(fds[0]) - defer syscall.Close(fds[1]) err = syscall.SetsockoptInt(fds[0], syscall.SOL_SOCKET, syscall.SO_PASSCRED, 1) if err != nil { + syscall.Close(fds[0]) + syscall.Close(fds[1]) t.Fatalf("SetsockoptInt: %v", err) } srvFile := os.NewFile(uintptr(fds[0]), "server") + cliFile := os.NewFile(uintptr(fds[1]), "client") defer srvFile.Close() + defer cliFile.Close() + srv, err := net.FileConn(srvFile) if err != nil { t.Errorf("FileConn: %v", err) @@ -55,8 +58,6 @@ func TestSCMCredentials(t *testing.T) { } defer srv.Close() - cliFile := os.NewFile(uintptr(fds[1]), "client") - defer cliFile.Close() cli, err := net.FileConn(cliFile) if err != nil { t.Errorf("FileConn: %v", err) diff --git a/src/syscall/syscall_unix_test.go b/src/syscall/syscall_unix_test.go index ce56c21ff2..af0bc856ee 100644 --- a/src/syscall/syscall_unix_test.go +++ b/src/syscall/syscall_unix_test.go @@ -159,8 +159,6 @@ func TestPassFD(t *testing.T) { if err != nil { t.Fatalf("Socketpair: %v", err) } - defer syscall.Close(fds[0]) - defer syscall.Close(fds[1]) writeFile := os.NewFile(uintptr(fds[0]), "child-writes") readFile := os.NewFile(uintptr(fds[1]), "parent-reads") defer writeFile.Close() |
