summaryrefslogtreecommitdiff
path: root/src/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg')
-rw-r--r--src/pkg/net/http/triv.go1
-rw-r--r--src/pkg/os/doc.go7
-rw-r--r--src/pkg/os/exec_plan9.go3
-rw-r--r--src/pkg/os/exec_unix.go3
-rw-r--r--src/pkg/os/exec_windows.go5
-rw-r--r--src/pkg/os/os_test.go2
6 files changed, 12 insertions, 9 deletions
diff --git a/src/pkg/net/http/triv.go b/src/pkg/net/http/triv.go
index c88a0fbce7..269af0ca3d 100644
--- a/src/pkg/net/http/triv.go
+++ b/src/pkg/net/http/triv.go
@@ -108,7 +108,6 @@ func DateServer(rw http.ResponseWriter, req *http.Request) {
fmt.Fprintf(rw, "fork/exec: %s\n", err)
return
}
- defer p.Release()
io.Copy(rw, r)
wait, err := p.Wait(0)
if err != nil {
diff --git a/src/pkg/os/doc.go b/src/pkg/os/doc.go
index ef857c0429..546f864714 100644
--- a/src/pkg/os/doc.go
+++ b/src/pkg/os/doc.go
@@ -11,6 +11,13 @@ func FindProcess(pid int) (p *Process, err error) {
return findProcess(pid)
}
+// Release releases any resources associated with the Process p,
+// rendering it unusable in the future.
+// Release only needs to be called if Wait is not.
+func (p *Process) Release() error {
+ return p.release()
+}
+
// Hostname returns the host name reported by the kernel.
func Hostname() (name string, err error) {
return hostname()
diff --git a/src/pkg/os/exec_plan9.go b/src/pkg/os/exec_plan9.go
index 1c9e2b997f..a941d12660 100644
--- a/src/pkg/os/exec_plan9.go
+++ b/src/pkg/os/exec_plan9.go
@@ -94,8 +94,7 @@ func (p *Process) Wait() (ps *ProcessState, err error) {
return ps, nil
}
-// Release releases any resources associated with the Process.
-func (p *Process) Release() error {
+func (p *Process) release() error {
// NOOP for Plan 9.
p.Pid = -1
// no need for a finalizer anymore
diff --git a/src/pkg/os/exec_unix.go b/src/pkg/os/exec_unix.go
index 8d000e9ef1..3f89fe8238 100644
--- a/src/pkg/os/exec_unix.go
+++ b/src/pkg/os/exec_unix.go
@@ -51,8 +51,7 @@ func (p *Process) Signal(sig Signal) error {
return nil
}
-// Release releases any resources associated with the Process.
-func (p *Process) Release() error {
+func (p *Process) release() error {
// NOOP for unix.
p.Pid = -1
// no need for a finalizer anymore
diff --git a/src/pkg/os/exec_windows.go b/src/pkg/os/exec_windows.go
index dab0dc9757..3d07ab7c92 100644
--- a/src/pkg/os/exec_windows.go
+++ b/src/pkg/os/exec_windows.go
@@ -14,6 +14,7 @@ import (
// Wait waits for the Process to exit or stop, and then returns a
// ProcessState describing its status and an error, if any.
+// Wait releases any resources associated with the Process.
func (p *Process) Wait() (ps *ProcessState, err error) {
s, e := syscall.WaitForSingleObject(syscall.Handle(p.handle), syscall.INFINITE)
switch s {
@@ -30,6 +31,7 @@ func (p *Process) Wait() (ps *ProcessState, err error) {
return nil, NewSyscallError("GetExitCodeProcess", e)
}
p.done = true
+ defer p.Release()
return &ProcessState{p.Pid, syscall.WaitStatus{Status: s, ExitCode: ec}, new(syscall.Rusage)}, nil
}
@@ -46,8 +48,7 @@ func (p *Process) Signal(sig Signal) error {
return syscall.Errno(syscall.EWINDOWS)
}
-// Release releases any resources associated with the Process.
-func (p *Process) Release() error {
+func (p *Process) release() error {
if p.handle == uintptr(syscall.InvalidHandle) {
return syscall.EINVAL
}
diff --git a/src/pkg/os/os_test.go b/src/pkg/os/os_test.go
index 02f75b2a73..d1e241f006 100644
--- a/src/pkg/os/os_test.go
+++ b/src/pkg/os/os_test.go
@@ -530,7 +530,6 @@ func exec(t *testing.T, dir, cmd string, args []string, expect string) {
if err != nil {
t.Fatalf("StartProcess: %v", err)
}
- defer p.Release()
w.Close()
var b bytes.Buffer
@@ -848,7 +847,6 @@ func run(t *testing.T, cmd []string) string {
if err != nil {
t.Fatal(err)
}
- defer p.Release()
w.Close()
var b bytes.Buffer