]> Cypherpunks repositories - gostls13.git/commitdiff
os/exec: make sure file is not closed early in leaked fd test
authorIan Lance Taylor <iant@golang.org>
Thu, 2 Feb 2012 00:37:02 +0000 (16:37 -0800)
committerIan Lance Taylor <iant@golang.org>
Thu, 2 Feb 2012 00:37:02 +0000 (16:37 -0800)
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

src/pkg/os/exec/exec_test.go

index d456dfb53d3e045c0e86ff20907612d33be1b210..d00d12008f75030117144987d5ff01d67ac7e49f 100644 (file)
@@ -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])