]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: don't defer close raw Socketpair fds in tests
authorTobias Klauser <tklauser@distanz.ch>
Tue, 13 Apr 2021 09:01:13 +0000 (11:01 +0200)
committerTobias Klauser <tobias.klauser@gmail.com>
Wed, 14 Apr 2021 05:49:15 +0000 (05:49 +0000)
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>
src/syscall/creds_test.go
src/syscall/syscall_unix_test.go

index 463033d558066abf728f20aa11d1571537db4db8..736b497bc40302b9fab4155588a2aace177093b7 100644 (file)
@@ -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)
index ce56c21ff26382a49185fa8be014eeb4a2b99d14..af0bc856ee8f9dc3c092492ae093591d4b9f003f 100644 (file)
@@ -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()