From 25fac919d94fa8b8602cc15d15915b136a7109a4 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 20 Oct 2021 00:41:20 -0600 Subject: [PATCH] windows/svc: do not close service handle The documentation [1] says "The service status handle does not have to be closed." That makes it seem like it's optional. But actually, closing it raises a user exception, because it's not a legitimate handle to close. This commit also adds the right go build comments with a `go fmt` pass. [1] https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-registerservicectrlhandlerexa Change-Id: Ibf67c0e8d94c87068720472009b24cecdfda6519 Reviewed-on: https://go-review.googlesource.com/c/sys/+/357250 Trust: Jason A. Donenfeld Run-TryBot: Jason A. Donenfeld TryBot-Result: Go Bot Reviewed-by: Brad Fitzpatrick --- windows/svc/security.go | 1 + windows/svc/service.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/windows/svc/security.go b/windows/svc/security.go index ef719c17..351d286f 100644 --- a/windows/svc/security.go +++ b/windows/svc/security.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build windows // +build windows package svc diff --git a/windows/svc/service.go b/windows/svc/service.go index 46c73a52..9ad6eb4d 100644 --- a/windows/svc/service.go +++ b/windows/svc/service.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build windows // +build windows // Package svc provides everything required to build Windows service. @@ -201,7 +202,6 @@ func serviceMain(argc uint32, argv **uint16) uintptr { theService.h = handle defer func() { theService.h = 0 - windows.CloseHandle(handle) }() var args16 []*uint16 hdr := (*unsafeheader.Slice)(unsafe.Pointer(&args16))