From 90b6938ca04d49240ddcd1a50650489f3fe3f26b Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 4 Feb 2019 08:22:49 +0100 Subject: [PATCH] Stop checking for valid handle in DevInfo.Close() User should not have called or deferred the Close() method should SetupDiGetClassDevsEx() return an error (and invalid handle). And even if user does that, a SetupDiDestroyDeviceInfoList(INVALID_HANDLE_VALUE) is harmless. It just returns ERROR_INVALID_HANDLE - we have a unit test for this in TestSetupDiDestroyDeviceInfoList(). Signed-off-by: Simon Rozman --- setupapi/types_windows.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/setupapi/types_windows.go b/setupapi/types_windows.go index e2617a4..bc6f66b 100644 --- a/setupapi/types_windows.go +++ b/setupapi/types_windows.go @@ -25,11 +25,7 @@ type DevInfo windows.Handle // Close function deletes a device information set and frees all associated memory. func (h DevInfo) Close() error { - if h != DevInfo(windows.InvalidHandle) { - return SetupDiDestroyDeviceInfoList(h) - } - - return nil + return SetupDiDestroyDeviceInfoList(h) } const (