[REGE[REGEDIT]

- Katayama Hirofumi: Don't leak open handles to keys.
- Katayama Hirofumi: Misc code changes/ cleanup.
See issue #5547 for more details.

svn path=/trunk/; revision=48934
This commit is contained in:
Aleksey Bragin 2010-09-29 21:52:16 +00:00
parent 26adfda6bd
commit 24e16c3ff8

View file

@ -95,7 +95,7 @@ static void OnInitMenu(HWND hWnd)
dwIndex = 0; dwIndex = 0;
do do
{ {
cbValueName = sizeof(szValueName) / sizeof(szValueName[0]); cbValueName = COUNT_OF(szValueName);
cbValueData = sizeof(abValueData); cbValueData = sizeof(abValueData);
lResult = RegEnumValue(hKey, dwIndex, szValueName, &cbValueName, NULL, &dwType, abValueData, &cbValueData); lResult = RegEnumValue(hKey, dwIndex, szValueName, &cbValueName, NULL, &dwType, abValueData, &cbValueData);
if ((lResult == ERROR_SUCCESS) && (dwType == REG_SZ)) if ((lResult == ERROR_SUCCESS) && (dwType == REG_SZ))
@ -521,7 +521,7 @@ BOOL CopyKeyName(HWND hWnd, HKEY hRootKey, LPCTSTR keyName)
if (!GetKeyName(szBuffer, COUNT_OF(szBuffer), hRootKey, keyName)) if (!GetKeyName(szBuffer, COUNT_OF(szBuffer), hRootKey, keyName))
goto done; goto done;
hGlobal = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(szBuffer) + 1) * sizeof(TCHAR)); hGlobal = GlobalAlloc(GMEM_MOVEABLE, (lstrlen(szBuffer) + 1) * sizeof(TCHAR));
if (!hGlobal) if (!hGlobal)
goto done; goto done;
@ -553,21 +553,18 @@ static BOOL CreateNewValue(HKEY hRootKey, LPCTSTR pszKeyPath, DWORD dwType)
HKEY hKey; HKEY hKey;
LVFINDINFO lvfi; LVFINDINFO lvfi;
if (RegOpenKey(hRootKey, pszKeyPath, &hKey) != ERROR_SUCCESS) if (RegOpenKeyEx(hRootKey, pszKeyPath, 0, KEY_QUERY_VALUE | KEY_SET_VALUE,
&hKey) != ERROR_SUCCESS)
return FALSE; return FALSE;
LoadString(hInst, IDS_NEW_VALUE, szNewValueFormat, sizeof(szNewValueFormat) LoadString(hInst, IDS_NEW_VALUE, szNewValueFormat, COUNT_OF(szNewValueFormat));
/ sizeof(szNewValueFormat[0]));
do do
{ {
_sntprintf(szNewValue, sizeof(szNewValue) / sizeof(szNewValue[0]), wsprintf(szNewValue, szNewValueFormat, iIndex++);
szNewValueFormat, iIndex++);
cbData = sizeof(data); cbData = sizeof(data);
lResult = RegQueryValueEx(hKey, szNewValue, NULL, &dwExistingType, data, &cbData); lResult = RegQueryValueEx(hKey, szNewValue, NULL, &dwExistingType, data, &cbData);
} } while(lResult == ERROR_SUCCESS);
while(lResult == ERROR_SUCCESS);
switch(dwType) { switch(dwType) {
case REG_DWORD: case REG_DWORD:
@ -589,8 +586,11 @@ static BOOL CreateNewValue(HKEY hRootKey, LPCTSTR pszKeyPath, DWORD dwType)
} }
memset(data, 0, cbData); memset(data, 0, cbData);
lResult = RegSetValueEx(hKey, szNewValue, 0, dwType, data, cbData); lResult = RegSetValueEx(hKey, szNewValue, 0, dwType, data, cbData);
RegCloseKey(hKey);
if (lResult != ERROR_SUCCESS) if (lResult != ERROR_SUCCESS)
{
return FALSE; return FALSE;
}
RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath); RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);
@ -862,7 +862,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
} }
} }
if (GetFocus() == g_pChildWnd->hTreeWnd) else if (GetFocus() == g_pChildWnd->hTreeWnd)
{ {
/* Get focused entry of treeview (if any) */ /* Get focused entry of treeview (if any) */
HTREEITEM hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd); HTREEITEM hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
@ -905,8 +905,8 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
} }
} }
} else }
if (GetFocus() == g_pChildWnd->hTreeWnd) else if (GetFocus() == g_pChildWnd->hTreeWnd)
{ {
if (keyPath == 0 || *keyPath == 0) if (keyPath == 0 || *keyPath == 0)
{ {
@ -919,6 +919,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
} }
break; break;
}
case ID_EDIT_NEW_STRINGVALUE: case ID_EDIT_NEW_STRINGVALUE:
CreateNewValue(hKeyRoot, keyPath, REG_SZ); CreateNewValue(hKeyRoot, keyPath, REG_SZ);
break; break;
@ -934,8 +935,6 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_EDIT_NEW_EXPANDABLESTRINGVALUE: case ID_EDIT_NEW_EXPANDABLESTRINGVALUE:
CreateNewValue(hKeyRoot, keyPath, REG_EXPAND_SZ); CreateNewValue(hKeyRoot, keyPath, REG_EXPAND_SZ);
break; break;
}
case ID_EDIT_FIND: case ID_EDIT_FIND:
FindDialog(hWnd); FindDialog(hWnd);
break; break;