[REGEDIT]
authorThomas Faber <thomas.faber@reactos.org>
Mon, 31 Dec 2012 17:10:15 +0000 (17:10 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Mon, 31 Dec 2012 17:10:15 +0000 (17:10 +0000)
- Fix a handle leak. Patch by Edijs Kolesnikovičs.
CORE-6853 #resolve

svn path=/trunk/; revision=58069

reactos/base/applications/regedit/settings.c

index 1d562ac..10a1e55 100644 (file)
@@ -116,49 +116,45 @@ extern void SaveSettings(void)
 
     if (RegCreateKeyW(HKEY_CURRENT_USER, g_szGeneralRegKey, &hKey) == ERROR_SUCCESS)
     {
-        if (RegOpenKeyW(HKEY_CURRENT_USER, g_szGeneralRegKey, &hKey) == ERROR_SUCCESS)
+        RegistryBinaryConfig tConfig;
+        DWORD iBufferSize = sizeof(tConfig);
+        WCHAR szBuffer[MAX_PATH];
+        LPCWSTR keyPath, rootName;
+        HKEY hRootKey;
+
+        /* Save key position */
+        keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
+        if (keyPath)
         {
-            RegistryBinaryConfig tConfig;
-            DWORD iBufferSize = sizeof(tConfig);
-            WCHAR szBuffer[MAX_PATH];
-            LPCWSTR keyPath, rootName;
-            HKEY hRootKey;
-
-            /* Save key position */
-            keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
-            if (keyPath)
-            {
-                rootName = get_root_key_name(hRootKey);
+            rootName = get_root_key_name(hRootKey);
 
-                /* Load "My Computer" string and complete it */
-                LoadStringW(hInst, IDS_MY_COMPUTER, szBuffer, COUNT_OF(szBuffer));
-                wcscat(szBuffer, L"\\"); wcscat(szBuffer, rootName);
-                wcscat(szBuffer, L"\\"); wcscat(szBuffer, keyPath);
+            /* Load "My Computer" string and complete it */
+            LoadStringW(hInst, IDS_MY_COMPUTER, szBuffer, COUNT_OF(szBuffer));
+            wcscat(szBuffer, L"\\"); wcscat(szBuffer, rootName);
+            wcscat(szBuffer, L"\\"); wcscat(szBuffer, keyPath);
 
-                RegSetValueExW(hKey, L"LastKey", 0, REG_SZ, (LPBYTE)szBuffer, (DWORD)wcslen(szBuffer) * sizeof(WCHAR));
-            }
+            RegSetValueExW(hKey, L"LastKey", 0, REG_SZ, (LPBYTE)szBuffer, (DWORD)wcslen(szBuffer) * sizeof(WCHAR));
+        }
 
-            /* Get statusbar settings */
-            tConfig.StatusBarVisible = ((GetMenuState(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND) & MF_CHECKED) ? 1 : 0);
+        /* Get statusbar settings */
+        tConfig.StatusBarVisible = ((GetMenuState(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND) & MF_CHECKED) ? 1 : 0);
 
-            /* Get splitter position */
-            tConfig.TreeViewSize = g_pChildWnd->nSplitPos;
+        /* Get splitter position */
+        tConfig.TreeViewSize = g_pChildWnd->nSplitPos;
 
-            /* Get list view column width*/
-            tConfig.NameColumnSize = ListView_GetColumnWidth(g_pChildWnd->hListWnd, 0);
-            tConfig.TypeColumnSize = ListView_GetColumnWidth(g_pChildWnd->hListWnd, 1);
-            tConfig.DataColumnSize = ListView_GetColumnWidth(g_pChildWnd->hListWnd, 2);
+        /* Get list view column width*/
+        tConfig.NameColumnSize = ListView_GetColumnWidth(g_pChildWnd->hListWnd, 0);
+        tConfig.TypeColumnSize = ListView_GetColumnWidth(g_pChildWnd->hListWnd, 1);
+        tConfig.DataColumnSize = ListView_GetColumnWidth(g_pChildWnd->hListWnd, 2);
 
-            /* Get program window settings */
-            tConfig.tPlacement.length = sizeof(WINDOWPLACEMENT);
-            GetWindowPlacement(hFrameWnd , &tConfig.tPlacement);
+        /* Get program window settings */
+        tConfig.tPlacement.length = sizeof(WINDOWPLACEMENT);
+        GetWindowPlacement(hFrameWnd , &tConfig.tPlacement);
 
-            /* Save all the data */
-            RegSetValueExW(hKey, L"View", 0, REG_BINARY, (LPBYTE)&tConfig, iBufferSize);
+        /* Save all the data */
+        RegSetValueExW(hKey, L"View", 0, REG_BINARY, (LPBYTE)&tConfig, iBufferSize);
 
-            RegCloseKey(hKey);
-        }
+        RegCloseKey(hKey);
     }
 }
-
 /* EOF */