https://git.reactos.org/?p=reactos.git;a=commitdiff;h=36051d30650f0d89975fb18e08a9794f5fda1f03

commit 36051d30650f0d89975fb18e08a9794f5fda1f03
Author:     Timo Kreuzer <timo.kreu...@reactos.org>
AuthorDate: Sat Mar 17 14:23:34 2018 +0100
Commit:     Timo Kreuzer <timo.kreu...@reactos.org>
CommitDate: Mon Aug 20 22:10:04 2018 +0200

    [SYSSETUP] Fix handling of the status message window
    
    This fixes a race condition, where the message thread was still running 
when InstallReactOS returned and syssetup.dll was unloaded by the caller 
(setup.exe).
---
 dll/win32/syssetup/install.c | 45 +++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/dll/win32/syssetup/install.c b/dll/win32/syssetup/install.c
index 63fa4a28e9..fa1d52b8a1 100644
--- a/dll/win32/syssetup/install.c
+++ b/dll/win32/syssetup/install.c
@@ -552,9 +552,9 @@ static DWORD WINAPI
 ShowStatusMessageThread(
     IN LPVOID lpParameter)
 {
-    HWND *phWnd = (HWND *)lpParameter;
     HWND hWnd, hItem;
     MSG Msg;
+    UNREFERENCED_PARAMETER(lpParameter);
 
     hWnd = CreateDialogParam(hDllInstance,
                              MAKEINTRESOURCE(IDD_STATUSWINDOW_DLG),
@@ -563,7 +563,6 @@ ShowStatusMessageThread(
                              (LPARAM)NULL);
     if (!hWnd)
         return 0;
-    *phWnd = hWnd;
 
     ShowWindow(hWnd, SW_SHOW);
 
@@ -580,6 +579,8 @@ ShowStatusMessageThread(
         DispatchMessage(&Msg);
     }
 
+    EndDialog(hWnd, 0);
+
     return 0;
 }
 
@@ -667,7 +668,8 @@ cleanup:
 static BOOL
 CommonInstall(VOID)
 {
-    HWND hWnd = NULL;
+    HANDLE hThread = NULL;
+    BOOL bResult = FALSE;
 
     hSysSetupInf = SetupOpenInfFileW(L"syssetup.inf",
                                      NULL,
@@ -682,49 +684,54 @@ CommonInstall(VOID)
     if (!InstallSysSetupInfDevices())
     {
         FatalError("InstallSysSetupInfDevices() failed!\n");
-        goto error;
+        goto Exit;
     }
 
     if(!InstallSysSetupInfComponents())
     {
         FatalError("InstallSysSetupInfComponents() failed!\n");
-        goto error;
+        goto Exit;
     }
 
     if (!IsConsoleBoot())
     {
-        HANDLE hThread;
-
         hThread = CreateThread(NULL,
                                0,
                                ShowStatusMessageThread,
-                               (LPVOID)&hWnd,
+                               NULL,
                                0,
                                NULL);
-        if (hThread)
-            CloseHandle(hThread);
     }
 
     if (!EnableUserModePnpManager())
     {
         FatalError("EnableUserModePnpManager() failed!\n");
-        goto error;
+        goto Exit;
     }
 
     if (CMP_WaitNoPendingInstallEvents(INFINITE) != WAIT_OBJECT_0)
     {
         FatalError("CMP_WaitNoPendingInstallEvents() failed!\n");
-        goto error;
+        goto Exit;
     }
 
-    EndDialog(hWnd, 0);
-    return TRUE;
+    bResult = TRUE;
 
-error:
-    if (hWnd)
-        EndDialog(hWnd, 0);
-    SetupCloseInfFile(hSysSetupInf);
-    return FALSE;
+Exit:
+
+    if (bResult == FALSE)
+    {
+        SetupCloseInfFile(hSysSetupInf);
+    }
+
+    if (hThread != NULL)
+    {
+        PostThreadMessage(GetThreadId(hThread), WM_QUIT, 0, 0);
+        WaitForSingleObject(hThread, INFINITE);
+        CloseHandle(hThread);
+    }
+
+    return bResult;
 }
 
 /* Install a section of a .inf file

Reply via email to