From 4bf32102abfacf4917dd18d00673608a8fa877c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Thu, 5 May 2022 22:21:21 +0200 Subject: [PATCH] [SHELL32_APITEST] ShellExecCmdLine: Do **NOT** use TerminateProcess to close the opened windows. This design, introduced in 418edcd2b, is fundamentally flawed as it can also close windows unrelated to the running test (e.g. windows of programs that the user can start, while the test is running). But since we cannot do much better, mitigate instead the other main problem of this design: Just use PostMessageW(WM_CLOSE), as it used to be, instead of TerminateProcess(). Indeed, using TerminateProcess() otherwise could kill unrelated processes the test hasn't created. In particular it could kill the csrss.exe system process if, during the testing procedure, a hard-error popup shows up. And this is precisely the case when this test runs with limited memory, and a hard-error "Insufficient system resources exist to complete the requested service." arises. --- modules/rostests/apitests/shell32/ShellExecCmdLine.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp b/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp index e869e6deee5..218ff08ed88 100644 --- a/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp +++ b/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp @@ -609,13 +609,7 @@ static void CleanupNewlyCreatedWindows(void) } } if (!bFound) - { - DWORD dwPID; - GetWindowThreadProcessId(s_wi1.phwnd[i1], &dwPID); - HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, TRUE, dwPID); - TerminateProcess(hProcess, -1); - CloseHandle(hProcess); - } + PostMessageW(s_wi1.phwnd[i1], WM_CLOSE, 0, 0); } free(s_wi1.phwnd); ZeroMemory(&s_wi1, sizeof(s_wi1));