From 2683d3a1e5f86624b1227933ad620dde8aefa171 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Wed, 3 Jun 2015 18:12:07 +0200 Subject: server: Fix opening clipboard from multiple threads. --- dlls/user32/tests/clipboard.c | 14 ++++++++++++++ server/clipboard.c | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/dlls/user32/tests/clipboard.c b/dlls/user32/tests/clipboard.c index a9aef84..6f6cb39 100644 --- a/dlls/user32/tests/clipboard.c +++ b/dlls/user32/tests/clipboard.c @@ -24,9 +24,18 @@ #include "wingdi.h" #include "winuser.h" +static DWORD WINAPI open_clipboard_thread(LPVOID arg) +{ + HWND hWnd = arg; + ok(OpenClipboard(hWnd), "OpenClipboard second time in the same hwnd failed\n"); + return 0; +} + static void test_ClipboardOwner(void) { + HANDLE thread; HWND hWnd1, hWnd2; + DWORD dwret; BOOL ret; SetLastError(0xdeadbeef); @@ -56,6 +65,11 @@ static void test_ClipboardOwner(void) ok( ret, "CloseClipboard error %d\n", GetLastError()); ok(OpenClipboard(hWnd1), "OpenClipboard failed\n"); + thread = CreateThread(NULL, 0, open_clipboard_thread, hWnd1, 0, NULL); + ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError()); + dwret = WaitForSingleObject(thread, 1000); + ok(dwret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", dwret); + CloseHandle(thread); ok(OpenClipboard(hWnd1), "OpenClipboard second time in the same hwnd failed\n"); SetLastError(0xdeadbeef); diff --git a/server/clipboard.c b/server/clipboard.c index 9acee98..ad7ae6f 100644 --- a/server/clipboard.c +++ b/server/clipboard.c @@ -138,8 +138,9 @@ void cleanup_clipboard_thread(struct thread *thread) static int open_clipboard( struct clipboard *clipboard, user_handle_t win ) { win = get_user_full_handle( win ); - if (clipboard->open_thread && (clipboard->open_thread != current || clipboard->open_win != win)) + if (clipboard->open_thread) { + if (clipboard->open_win == win) return 1; set_error(STATUS_WAS_LOCKED); return 0; } -- 2.4.2