>From e229f9a118f8159219bdfbda3f9a8dbee78e5b4d Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov@codeweavers.com>
Date: Mon, 28 Nov 2011 23:32:59 +0300
Subject: [PATCH 5/5] Avoid extra checks that RegCloseKey() already does internally

---
 dlls/shlwapi/reg.c       |   35 +++++++++++++++++------------------
 dlls/shlwapi/regstream.c |    6 ++----
 2 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/dlls/shlwapi/reg.c b/dlls/shlwapi/reg.c
index 09fce55..d48d754 100644
--- a/dlls/shlwapi/reg.c
+++ b/dlls/shlwapi/reg.c
@@ -187,23 +187,22 @@ LONG WINAPI SHRegOpenUSKeyW(LPCWSTR Path, REGSAM AccessType, HUSKEY hRelativeUSK
  *  Success: ERROR_SUCCESS
  *  Failure: An error code from RegCloseKey().
  */
-LONG WINAPI SHRegCloseUSKey(
-        HUSKEY hUSKey) /* [I] Key to close */
+LONG WINAPI SHRegCloseUSKey(HUSKEY us_key)
 {
-    LPSHUSKEY hKey = hUSKey;
-    LONG ret = ERROR_SUCCESS;
+    LONG ret, code = ERROR_SUCCESS;
+    SHUSKEY *key = us_key;
 
-    if (hKey->HKCUkey)
-        ret = RegCloseKey(hKey->HKCUkey);
-    if (hKey->HKCUstart && hKey->HKCUstart != HKEY_CURRENT_USER)
-        ret = RegCloseKey(hKey->HKCUstart);
-    if (hKey->HKLMkey)
-        ret = RegCloseKey(hKey->HKLMkey);
-    if (hKey->HKLMstart && hKey->HKLMstart != HKEY_LOCAL_MACHINE)
-        ret = RegCloseKey(hKey->HKLMstart);
+    ret = RegCloseKey(key->HKCUkey);
+    if (ret) code = ret;
+    ret = RegCloseKey(key->HKCUstart);
+    if (ret) code = ret;
+    ret = RegCloseKey(key->HKLMkey);
+    if (ret) code = ret;
+    ret = RegCloseKey(key->HKLMstart);
+    if (ret) code = ret;
+    HeapFree(GetProcessHeap(), 0, key);
 
-    HeapFree(GetProcessHeap(), 0, hKey);
-    return ret;
+    return code;
 }
 
 /*************************************************************************
@@ -1166,7 +1165,7 @@ DWORD WINAPI SHGetValueA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue,
   {
     /* SHQueryValueEx expands Environment strings */
     dwRet = SHQueryValueExA(hSubKey ? hSubKey : hKey, lpszValue, 0, pwType, pvData, pcbData);
-    if (hSubKey) RegCloseKey(hSubKey);
+    RegCloseKey(hSubKey);
   }
   return dwRet;
 }
@@ -1191,7 +1190,7 @@ DWORD WINAPI SHGetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue,
   if (! dwRet)
   {
     dwRet = SHQueryValueExW(hSubKey ? hSubKey : hKey, lpszValue, 0, pwType, pvData, pcbData);
-    if (hSubKey) RegCloseKey(hSubKey);
+    RegCloseKey(hSubKey);
   }
   return dwRet;
 }
diff --git a/dlls/shlwapi/regstream.c b/dlls/shlwapi/regstream.c
index 1b0ca4e..7aefdf8 100644
--- a/dlls/shlwapi/regstream.c
+++ b/dlls/shlwapi/regstream.c
@@ -526,8 +526,7 @@ IStream * WINAPI SHOpenRegStream2A(HKEY hKey, LPCSTR pszSubkey,
   }
 
   HeapFree(GetProcessHeap(), 0, lpBuff);
-  if (hStrKey)
-    RegCloseKey(hStrKey);
+  RegCloseKey(hStrKey);
   return NULL;
 }
 
@@ -586,8 +585,7 @@ IStream * WINAPI SHOpenRegStream2W(HKEY hKey, LPCWSTR pszSubkey,
   }
 
   HeapFree(GetProcessHeap(), 0, lpBuff);
-  if (hStrKey)
-    RegCloseKey(hStrKey);
+  RegCloseKey(hStrKey);
   return NULL;
 }
 
-- 
1.5.6.5

