1
0
mirror of https://github.com/golang/go synced 2024-11-20 08:24:42 -07:00

syscall: fix creds_test to reliably close os.File

Before this patch the test would close the file descriptor but
not the os.File.  When the os.File was GC'ed, the finalizer
would close the file descriptor again.  That would cause
problems if the same file descriptor were returned by a later
call to open in another test.

On my system:

> GOGC=30 go test
--- FAIL: TestPassFD (0.04 seconds)
passfd_test.go:62: 	FileConn: dup: bad file descriptor
FAIL

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6776053
This commit is contained in:
Ian Lance Taylor 2012-10-26 10:31:03 -07:00
parent f9902c7197
commit 5611e8b59f

View File

@ -31,14 +31,18 @@ func TestSCMCredentials(t *testing.T) {
t.Fatalf("SetsockoptInt: %v", err) t.Fatalf("SetsockoptInt: %v", err)
} }
srv, err := net.FileConn(os.NewFile(uintptr(fds[0]), "")) srvFile := os.NewFile(uintptr(fds[0]), "server")
defer srvFile.Close()
srv, err := net.FileConn(srvFile)
if err != nil { if err != nil {
t.Errorf("FileConn: %v", err) t.Errorf("FileConn: %v", err)
return return
} }
defer srv.Close() defer srv.Close()
cli, err := net.FileConn(os.NewFile(uintptr(fds[1]), "")) cliFile := os.NewFile(uintptr(fds[1]), "client")
defer cliFile.Close()
cli, err := net.FileConn(cliFile)
if err != nil { if err != nil {
t.Errorf("FileConn: %v", err) t.Errorf("FileConn: %v", err)
return return