[PATCH v4 2/2] server: Do not detach windows if they are owned by another thread.

Rémi Bernon rbernon at codeweavers.com
Fri Nov 8 11:58:26 CST 2019


On thread destroy, a WM_WINE_DESTROYWINDOW is sent for the child windows
owned by other threads. However there's then a race condition between
these threads peeking for messages and the current thread detaching its
child windows from their owning threads -which clears their message
queues.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/user32/tests/msg.c | 3 +--
 server/window.c         | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/dlls/user32/tests/msg.c b/dlls/user32/tests/msg.c
index a1deab10de5..fac340744b6 100644
--- a/dlls/user32/tests/msg.c
+++ b/dlls/user32/tests/msg.c
@@ -8595,7 +8595,6 @@ static DWORD CALLBACK create_grand_child_thread( void *param )
     ok( !ret, "WaitForSingleObject returned %x, error: %u\n", ret, GetLastError() );
 
     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
-    todo_wine
     ok( !IsWindow( hchild ), "Child window not destroyed\n" );
 
     return 0;
@@ -8790,7 +8789,7 @@ static void test_interthread_messages(void)
     CloseHandle( wnd_event.start_event );
     CloseHandle( wnd_event.stop_event );
     flush_events();
-    ok_sequence(WmExitThreadSeq, "destroy child on thread exit", TRUE);
+    ok_sequence(WmExitThreadSeq, "destroy child on thread exit", FALSE);
     log_all_parent_messages--;
     DestroyWindow( wnd_event.hwnd );
 
diff --git a/server/window.c b/server/window.c
index c9b131cba5d..3985ea4eb20 100644
--- a/server/window.c
+++ b/server/window.c
@@ -1914,7 +1914,7 @@ void destroy_window( struct window *win )
         post_message( win->parent->handle, WM_PARENTNOTIFY, WM_DESTROY, win->handle );
     }
 
-    detach_window_thread( win );
+    if (win->thread == current) detach_window_thread( win );
     if (win->win_region) free_region( win->win_region );
     if (win->update_region) free_region( win->update_region );
     if (win->class) release_class( win->class );
-- 
2.24.0.rc2




More information about the wine-devel mailing list