windows/svc: use CloseServiceHandle for service handles

From MSDN on CreateServiceW:

  The returned handle is only valid for the process that called
  CreateService. It can be closed by calling the CloseServiceHandle
  function.

This isn't an actual kernel object to be closed with CloseHandle.

Change-Id: Iee225a666576d57a6c4864abef20206d54cbbce2
Reviewed-on: https://go-review.googlesource.com/c/sys/+/198298
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2019-10-01 22:21:21 +02:00
parent 3421d5a6bb
commit b397fe3ad8

View File

@@ -137,7 +137,7 @@ func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Se
err = updateSidType(h, c.SidType)
if err != nil {
windows.DeleteService(h)
windows.CloseHandle(h)
windows.CloseServiceHandle(h)
return nil, err
}
}
@@ -145,7 +145,7 @@ func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Se
err = updateDescription(h, c.Description)
if err != nil {
windows.DeleteService(h)
windows.CloseHandle(h)
windows.CloseServiceHandle(h)
return nil, err
}
}
@@ -153,7 +153,7 @@ func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Se
err = updateStartUp(h, c.DelayedAutoStart)
if err != nil {
windows.DeleteService(h)
windows.CloseHandle(h)
windows.CloseServiceHandle(h)
return nil, err
}
}