diff options
| author | Ian Lance Taylor <iant@golang.org> | 2012-02-01 16:37:02 -0800 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2012-02-01 16:37:02 -0800 |
| commit | 2b8d5be55f0201c3d4047ea8510b168eb37c5074 (patch) | |
| tree | dae4e1c70755ca63c3858d1c7d8314235f2bb92c /src/pkg/os/exec/exec_test.go | |
| parent | f3f5239d1e3e1acb299ef8a6a907df12713b9626 (diff) | |
| download | go-2b8d5be55f0201c3d4047ea8510b168eb37c5074.tar.xz | |
os/exec: make sure file is not closed early in leaked fd test
Without this change, fd3 can be collected by the garbage
collector and finalized, which causes the file descriptor to
be closed, which causes the call to os.Open to return 3 rather
than the expected descriptor number.
R=golang-dev, gri, bradfitz, bradfitz, iant
CC=golang-dev
https://golang.org/cl/5607056
Diffstat (limited to 'src/pkg/os/exec/exec_test.go')
| -rw-r--r-- | src/pkg/os/exec/exec_test.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/pkg/os/exec/exec_test.go b/src/pkg/os/exec/exec_test.go index d456dfb53d..d00d12008f 100644 --- a/src/pkg/os/exec/exec_test.go +++ b/src/pkg/os/exec/exec_test.go @@ -309,6 +309,12 @@ func TestHelperProcess(*testing.T) { f.Close() } } + // Referring to fd3 here ensures that it is not + // garbage collected, and therefore closed, while + // executing the wantfd loop above. It doesn't matter + // what we do with fd3 as long as we refer to it; + // closing it is the easy choice. + fd3.Close() os.Stderr.Write(bs) case "exit": n, _ := strconv.Atoi(args[0]) |
