diff options
author | Russ Cox <rsc@golang.org> | 2014-10-16 15:00:08 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-10-16 15:00:08 -0400 |
commit | 78db2eb9c66d478bee0d56edcc55d4f865f8c6c7 (patch) | |
tree | d08da7ddd82570422ae87dc9d3ac061f8ce3b648 /misc/cgo/test/issue8517_windows.go | |
parent | af64ab79c0ad72decf083d78cf54257d009741b5 (diff) | |
parent | 25c63c2c30f4807b073f849d248144d97893ce70 (diff) | |
download | go-78db2eb9c66d478bee0d56edcc55d4f865f8c6c7.tar.gz |
all: merge default branch into dev.garbage
hg was unable to create a CL on the code review server for this,
so I am submitting the merge by hand.
The only manual edits are in mgc0.c, to reapply the
removal of cached/ncached to the new code.
Diffstat (limited to 'misc/cgo/test/issue8517_windows.go')
-rw-r--r-- | misc/cgo/test/issue8517_windows.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/misc/cgo/test/issue8517_windows.go b/misc/cgo/test/issue8517_windows.go new file mode 100644 index 000000000..3782631e9 --- /dev/null +++ b/misc/cgo/test/issue8517_windows.go @@ -0,0 +1,45 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package cgotest + +//void testHandleLeaks(); +import "C" + +import ( + "syscall" + "testing" + "unsafe" +) + +var issue8517counter int + +var ( + kernel32 = syscall.MustLoadDLL("kernel32.dll") + getProcessHandleCount = kernel32.MustFindProc("GetProcessHandleCount") +) + +func processHandleCount(t *testing.T) int { + const current_process = ^uintptr(0) + var c uint32 + r, _, err := getProcessHandleCount.Call(current_process, uintptr(unsafe.Pointer(&c))) + if r == 0 { + t.Fatal(err) + } + return int(c) +} + +func test8517(t *testing.T) { + c1 := processHandleCount(t) + C.testHandleLeaks() + c2 := processHandleCount(t) + if c1+issue8517counter <= c2 { + t.Fatalf("too many handles leaked: issue8517counter=%v c1=%v c2=%v", issue8517counter, c1, c2) + } +} + +//export testHandleLeaksCallback +func testHandleLeaksCallback() { + issue8517counter++ +} |