issue8517_windows.go 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package cgotest
  5. //void testHandleLeaks();
  6. import "C"
  7. import (
  8. "syscall"
  9. "testing"
  10. "unsafe"
  11. )
  12. var issue8517counter int
  13. var (
  14. kernel32 = syscall.MustLoadDLL("kernel32.dll")
  15. getProcessHandleCount = kernel32.MustFindProc("GetProcessHandleCount")
  16. )
  17. func processHandleCount(t *testing.T) int {
  18. const current_process = ^uintptr(0)
  19. var c uint32
  20. r, _, err := getProcessHandleCount.Call(current_process, uintptr(unsafe.Pointer(&c)))
  21. if r == 0 {
  22. t.Fatal(err)
  23. }
  24. return int(c)
  25. }
  26. func test8517(t *testing.T) {
  27. c1 := processHandleCount(t)
  28. C.testHandleLeaks()
  29. c2 := processHandleCount(t)
  30. if c1+issue8517counter <= c2 {
  31. t.Fatalf("too many handles leaked: issue8517counter=%v c1=%v c2=%v", issue8517counter, c1, c2)
  32. }
  33. }
  34. //export testHandleLeaksCallback
  35. func testHandleLeaksCallback() {
  36. issue8517counter++
  37. }