mirror of
https://github.com/golang/go
synced 2024-11-26 08:48:13 -07:00
os: avoid finalizer race in windows process object
If proc.Release is called concurrently, a handle will be double-freed. Change-Id: I0c0c32e312e07bc8615e0bf9e9b691214444d8d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/322510 Trust: Jason A. Donenfeld <Jason@zx2c4.com> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
105c5b50e0
commit
3a9d906edc
@ -69,7 +69,7 @@ func (p *Process) signal(sig Signal) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) release() error {
|
func (p *Process) release() error {
|
||||||
handle := atomic.LoadUintptr(&p.handle)
|
handle := atomic.SwapUintptr(&p.handle, uintptr(syscall.InvalidHandle))
|
||||||
if handle == uintptr(syscall.InvalidHandle) {
|
if handle == uintptr(syscall.InvalidHandle) {
|
||||||
return syscall.EINVAL
|
return syscall.EINVAL
|
||||||
}
|
}
|
||||||
@ -77,7 +77,6 @@ func (p *Process) release() error {
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
return NewSyscallError("CloseHandle", e)
|
return NewSyscallError("CloseHandle", e)
|
||||||
}
|
}
|
||||||
atomic.StoreUintptr(&p.handle, uintptr(syscall.InvalidHandle))
|
|
||||||
// no need for a finalizer anymore
|
// no need for a finalizer anymore
|
||||||
runtime.SetFinalizer(p, nil)
|
runtime.SetFinalizer(p, nil)
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user