gameux: Do not use RegCloseKey on invalid/uninitialized registry key handle (Coverity)

Frédéric Delanoy frederic.delanoy at gmail.com
Wed Nov 30 09:26:17 CST 2011


CID 4665

RegCloseKey(hKey) was called even if the preceding RegOpenKeyExW failed
---
 dlls/gameux/gamestatistics.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/dlls/gameux/gamestatistics.c b/dlls/gameux/gamestatistics.c
index 96b35d5..ccacbcb 100644
--- a/dlls/gameux/gamestatistics.c
+++ b/dlls/gameux/gamestatistics.c
@@ -390,17 +390,18 @@ static HRESULT GAMEUX_getAppIdFromGDFPath(
         /* game is registered, let's read it's application id from registry */
         hr = GAMEUX_buildGameRegistryPath(installScope, &instanceId, &lpRegistryPath);
 
-    if(SUCCEEDED(hr))
+    if(SUCCEEDED(hr)) {
         hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE,
                 lpRegistryPath, 0, KEY_READ | KEY_WOW64_64KEY, &hKey));
-
-    if(SUCCEEDED(hr))
-        hr = HRESULT_FROM_WIN32(RegGetValueW(hKey,
-                NULL, sApplicationId, RRF_RT_REG_SZ,
-                NULL, lpApplicationId, &dwLength));
+        if(SUCCEEDED(hr)) {
+            hr = HRESULT_FROM_WIN32(RegGetValueW(hKey,
+                    NULL, sApplicationId, RRF_RT_REG_SZ,
+                    NULL, lpApplicationId, &dwLength));
+            RegCloseKey(hKey);
+        }
+    }
 
     HeapFree(GetProcessHeap(), 0, lpRegistryPath);
-    RegCloseKey(hKey);
 
     TRACE("found app id: %s, return: %#x\n", debugstr_w(lpApplicationId), hr);
     return hr;
-- 
1.7.7.2




More information about the wine-patches mailing list