invoke winreg.CloseKey only if winreg.OpenKey succeed
@@ -216,6 +216,7 @@ def find_windows_10_sdk():
for key, subkey in hives:
try:
hkey = winreg.OpenKey(key, r'%s\Microsoft\Microsoft SDKs\Windows\v10.0' % subkey)
+ try:
installation_folder, _ = winreg.QueryValueEx(hkey, 'InstallationFolder')
if os.path.isdir(installation_folder):
include_dir = os.path.join(installation_folder, 'include')
@@ -228,6 +229,8 @@ def find_windows_10_sdk():
pass
finally:
winreg.CloseKey(hkey)
+ except OSError: # Raised by OpenKey/Ex if the function fails.
+ pass
return None
