Author: hbelusca Date: Fri Jul 1 21:23:47 2016 New Revision: 71716
URL: http://svn.reactos.org/svn/reactos?rev=71716&view=rev Log: [TASKMGR] debug.c: - Don't hardcode the size of the string buffers. - Only use KEY_QUERY_VALUE right to query the values inside a registry key. - Fix size parameter value given to RegQueryValueEx. - Use ZeroMemory instead of memset(..., 0, ...) (heh, we're in Win32 guys!) - Close thread-and-process handles of the spawned debugger app.
Modified: trunk/reactos/base/applications/taskmgr/debug.c
Modified: trunk/reactos/base/applications/taskmgr/debug.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/taskmgr/d... ============================================================================== --- trunk/reactos/base/applications/taskmgr/debug.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/taskmgr/debug.c [iso-8859-1] Fri Jul 1 21:23:47 2016 @@ -42,31 +42,31 @@ if (dwProcessId == 0) return;
- LoadStringW(hInst, IDS_MSG_WARNINGDEBUG, szTemp, 256); - LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTempA, 256); + LoadStringW(hInst, IDS_MSG_WARNINGDEBUG, szTemp, ARRAYSIZE(szTemp)); + LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTempA, ARRAYSIZE(szTempA));
- if (MessageBoxW(hMainWnd, szTemp, szTempA, MB_YESNO|MB_ICONWARNING) != IDYES) + if (MessageBoxW(hMainWnd, szTemp, szTempA, MB_YESNO | MB_ICONWARNING) != IDYES) { - GetLastErrorText(strErrorText, 260); - LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256); - MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP); + GetLastErrorText(strErrorText, ARRAYSIZE(strErrorText)); + LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, ARRAYSIZE(szTemp)); + MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP); return; }
- if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\Microsoft\Windows NT\CurrentVersion\AeDebug", 0, KEY_READ, &hKey) != ERROR_SUCCESS) + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\Microsoft\Windows NT\CurrentVersion\AeDebug", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) { - GetLastErrorText(strErrorText, 260); - LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256); - MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP); + GetLastErrorText(strErrorText, ARRAYSIZE(strErrorText)); + LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, ARRAYSIZE(szTemp)); + MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP); return; }
- dwDebuggerSize = 260; + dwDebuggerSize = sizeof(strDebugger); if (RegQueryValueExW(hKey, L"Debugger", NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) != ERROR_SUCCESS) { - GetLastErrorText(strErrorText, 260); - LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256); - MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP); + GetLastErrorText(strErrorText, ARRAYSIZE(strErrorText)); + LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, ARRAYSIZE(szTemp)); + MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP); RegCloseKey(hKey); return; } @@ -76,22 +76,27 @@ hDebugEvent = CreateEventW(NULL, FALSE, FALSE, NULL); if (!hDebugEvent) { - GetLastErrorText(strErrorText, 260); - LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256); - MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP); + GetLastErrorText(strErrorText, ARRAYSIZE(strErrorText)); + LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, ARRAYSIZE(szTemp)); + MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP); return; }
wsprintfW(strDebugPath, strDebugger, dwProcessId, hDebugEvent);
- memset(&pi, 0, sizeof(PROCESS_INFORMATION)); - memset(&si, 0, sizeof(STARTUPINFOW)); - si.cb = sizeof(STARTUPINFOW); + ZeroMemory(&pi, sizeof(pi)); + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); if (!CreateProcessW(NULL, strDebugPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { - GetLastErrorText(strErrorText, 260); - LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256); - MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP); + GetLastErrorText(strErrorText, ARRAYSIZE(strErrorText)); + LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, ARRAYSIZE(szTemp)); + MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP); + } + else + { + CloseHandle(pi.hThread); + CloseHandle(pi.hProcess); }
CloseHandle(hDebugEvent);