1
0
mirror of https://github.com/golang/go synced 2024-11-23 08:10:03 -07:00

os: keep attr.Files alive when calling StartProcess

Updates #34810
Fixes #34858

Change-Id: Ie934861e51eeafe8a7fd6653c4223a5f5d45efe8
Reviewed-on: https://go-review.googlesource.com/c/go/+/201198
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Ian Lance Taylor 2019-10-15 07:52:23 -07:00
parent 831e3cfaa5
commit 52e5987f5d

View File

@ -7,6 +7,7 @@
package os
import (
"runtime"
"syscall"
)
@ -49,9 +50,14 @@ func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
}
pid, h, e := syscall.StartProcess(name, argv, sysattr)
// Make sure we don't run the finalizers of attr.Files.
runtime.KeepAlive(attr)
if e != nil {
return nil, &PathError{"fork/exec", name, e}
}
return newProcess(pid, h), nil
}