Skip to content

Commit 24e16c3

Browse files
committed
[REGE[REGEDIT]
- Katayama Hirofumi: Don't leak open handles to keys. - Katayama Hirofumi: Misc code changes/ cleanup. See issue reactos#5547 for more details. svn path=/trunk/; revision=48934
1 parent 26adfda commit 24e16c3

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

reactos/base/applications/regedit/framewnd.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void OnInitMenu(HWND hWnd)
9595
dwIndex = 0;
9696
do
9797
{
98-
cbValueName = sizeof(szValueName) / sizeof(szValueName[0]);
98+
cbValueName = COUNT_OF(szValueName);
9999
cbValueData = sizeof(abValueData);
100100
lResult = RegEnumValue(hKey, dwIndex, szValueName, &cbValueName, NULL, &dwType, abValueData, &cbValueData);
101101
if ((lResult == ERROR_SUCCESS) && (dwType == REG_SZ))
@@ -521,7 +521,7 @@ BOOL CopyKeyName(HWND hWnd, HKEY hRootKey, LPCTSTR keyName)
521521
if (!GetKeyName(szBuffer, COUNT_OF(szBuffer), hRootKey, keyName))
522522
goto done;
523523

524-
hGlobal = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(szBuffer) + 1) * sizeof(TCHAR));
524+
hGlobal = GlobalAlloc(GMEM_MOVEABLE, (lstrlen(szBuffer) + 1) * sizeof(TCHAR));
525525
if (!hGlobal)
526526
goto done;
527527

@@ -553,21 +553,18 @@ static BOOL CreateNewValue(HKEY hRootKey, LPCTSTR pszKeyPath, DWORD dwType)
553553
HKEY hKey;
554554
LVFINDINFO lvfi;
555555

556-
if (RegOpenKey(hRootKey, pszKeyPath, &hKey) != ERROR_SUCCESS)
556+
if (RegOpenKeyEx(hRootKey, pszKeyPath, 0, KEY_QUERY_VALUE | KEY_SET_VALUE,
557+
&hKey) != ERROR_SUCCESS)
557558
return FALSE;
558559

559-
LoadString(hInst, IDS_NEW_VALUE, szNewValueFormat, sizeof(szNewValueFormat)
560-
/ sizeof(szNewValueFormat[0]));
560+
LoadString(hInst, IDS_NEW_VALUE, szNewValueFormat, COUNT_OF(szNewValueFormat));
561561

562562
do
563563
{
564-
_sntprintf(szNewValue, sizeof(szNewValue) / sizeof(szNewValue[0]),
565-
szNewValueFormat, iIndex++);
566-
564+
wsprintf(szNewValue, szNewValueFormat, iIndex++);
567565
cbData = sizeof(data);
568566
lResult = RegQueryValueEx(hKey, szNewValue, NULL, &dwExistingType, data, &cbData);
569-
}
570-
while(lResult == ERROR_SUCCESS);
567+
} while(lResult == ERROR_SUCCESS);
571568

572569
switch(dwType) {
573570
case REG_DWORD:
@@ -589,8 +586,11 @@ static BOOL CreateNewValue(HKEY hRootKey, LPCTSTR pszKeyPath, DWORD dwType)
589586
}
590587
memset(data, 0, cbData);
591588
lResult = RegSetValueEx(hKey, szNewValue, 0, dwType, data, cbData);
589+
RegCloseKey(hKey);
592590
if (lResult != ERROR_SUCCESS)
591+
{
593592
return FALSE;
593+
}
594594

595595
RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);
596596

@@ -862,7 +862,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
862862
}
863863
}
864864
}
865-
if (GetFocus() == g_pChildWnd->hTreeWnd)
865+
else if (GetFocus() == g_pChildWnd->hTreeWnd)
866866
{
867867
/* Get focused entry of treeview (if any) */
868868
HTREEITEM hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
@@ -905,8 +905,8 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
905905
}
906906
}
907907
}
908-
} else
909-
if (GetFocus() == g_pChildWnd->hTreeWnd)
908+
}
909+
else if (GetFocus() == g_pChildWnd->hTreeWnd)
910910
{
911911
if (keyPath == 0 || *keyPath == 0)
912912
{
@@ -918,7 +918,8 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
918918
RefreshTreeView(g_pChildWnd->hTreeWnd);
919919
}
920920
}
921-
break;
921+
break;
922+
}
922923
case ID_EDIT_NEW_STRINGVALUE:
923924
CreateNewValue(hKeyRoot, keyPath, REG_SZ);
924925
break;
@@ -928,14 +929,12 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
928929
case ID_EDIT_NEW_DWORDVALUE:
929930
CreateNewValue(hKeyRoot, keyPath, REG_DWORD);
930931
break;
931-
case ID_EDIT_NEW_MULTISTRINGVALUE:
932+
case ID_EDIT_NEW_MULTISTRINGVALUE:
932933
CreateNewValue(hKeyRoot, keyPath, REG_MULTI_SZ);
933934
break;
934-
case ID_EDIT_NEW_EXPANDABLESTRINGVALUE:
935+
case ID_EDIT_NEW_EXPANDABLESTRINGVALUE:
935936
CreateNewValue(hKeyRoot, keyPath, REG_EXPAND_SZ);
936937
break;
937-
938-
}
939938
case ID_EDIT_FIND:
940939
FindDialog(hWnd);
941940
break;

0 commit comments

Comments
 (0)