Author: hbelusca
Date: Sun Apr  5 23:42:26 2015
New Revision: 67069

URL: http://svn.reactos.org/svn/reactos?rev=67069&view=rev
Log:
[KERNEL32]
- Use the correct console critical section when setting console control 
handlers.
- Hold the console critical section in FreeConsole (so that we avoid freeing 
the console while also running code in the console control dispatcher...).

Modified:
    trunk/reactos/dll/win32/kernel32/client/console/console.c

Modified: trunk/reactos/dll/win32/kernel32/client/console/console.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/console/console.c?rev=67069&r1=67068&r2=67069&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/console/console.c   [iso-8859-1] 
(original)
+++ trunk/reactos/dll/win32/kernel32/client/console/console.c   [iso-8859-1] 
Sun Apr  5 23:42:26 2015
@@ -1346,15 +1346,19 @@
 DECLSPEC_HOTPATCH
 FreeConsole(VOID)
 {
+    BOOL Success = TRUE;
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_FREECONSOLE FreeConsoleRequest = 
&ApiMessage.Data.FreeConsoleRequest;
     HANDLE ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
 
+    RtlEnterCriticalSection(&ConsoleLock);
+
     /* We must have a non-trivial handle to close */
     if (ConsoleHandle == NULL) // IsConsoleHandle(ConsoleHandle)
     {
         SetLastError(ERROR_INVALID_PARAMETER);
-        return FALSE;
+        Success = FALSE;
+        goto Quit;
     }
 
     /* Set up the data to send to the Console Server */
@@ -1370,7 +1374,8 @@
     if (!NT_SUCCESS(ApiMessage.Status))
     {
         BaseSetLastNTError(ApiMessage.Status);
-        return FALSE;
+        Success = FALSE;
+        goto Quit;
     }
 
     /* Reset the console handle */
@@ -1380,7 +1385,9 @@
     CloseHandle(InputWaitHandle);
     InputWaitHandle = INVALID_HANDLE_VALUE;
 
-    return TRUE;
+Quit:
+    RtlLeaveCriticalSection(&ConsoleLock);
+    return Success;
 }
 
 
@@ -2007,18 +2014,15 @@
 {
     BOOL Ret;
 
-    RtlEnterCriticalSection(&BaseDllDirectoryLock);
+    RtlEnterCriticalSection(&ConsoleLock);
+
     if (Add)
-    {
         Ret = AddConsoleCtrlHandler(HandlerRoutine);
-    }
     else
-    {
         Ret = RemoveConsoleCtrlHandler(HandlerRoutine);
-    }
-
-    RtlLeaveCriticalSection(&BaseDllDirectoryLock);
-    return(Ret);
+
+    RtlLeaveCriticalSection(&ConsoleLock);
+    return Ret;
 }
 
 


Reply via email to