hw/xwin: Avoid WIN_WINDOW_PROP races during Windows window destruction

The WIN_WINDOW_PROP is removed during WM_DESTROY handling, so it is not neccessary to
remove it in winDestroyWindowsWindow(), and doing so opens a race condition, as we may
attempt to access that property in the wndproc before the WM_DESTROY has completed.

A specific example of that race is if a WM_KILLFOCUS occurs in the window between property
removal and WM_DESTROY processing, where we will attempt to apply DeleteWindowFromAnyEvents()
on an invalid (null) WindowPtr.

Also guard against null WindowPtr in the WM_KILLFOCUS handler

See http://cygwin.com/ml/cygwin-xfree/2012-01/msg00009.html

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
This commit is contained in:
Jon TURNEY 2012-01-22 19:31:51 +00:00
parent 9a709d5028
commit bea6fb6c7a
2 changed files with 5 additions and 5 deletions

View File

@ -638,8 +638,6 @@ winDestroyWindowsWindow (WindowPtr pWin)
hIcon = (HICON)SendMessage(pWinPriv->hWnd, WM_GETICON, ICON_BIG, 0); hIcon = (HICON)SendMessage(pWinPriv->hWnd, WM_GETICON, ICON_BIG, 0);
hIconSm = (HICON)SendMessage(pWinPriv->hWnd, WM_GETICON, ICON_SMALL, 0); hIconSm = (HICON)SendMessage(pWinPriv->hWnd, WM_GETICON, ICON_SMALL, 0);
SetProp (pWinPriv->hWnd, WIN_WINDOW_PROP, NULL);
/* Destroy the Windows window */ /* Destroy the Windows window */
DestroyWindow (pWinPriv->hWnd); DestroyWindow (pWinPriv->hWnd);

View File

@ -713,9 +713,11 @@ winTopLevelWindowProc (HWND hwnd, UINT message,
/* Remove our keyboard hook if it is installed */ /* Remove our keyboard hook if it is installed */
winRemoveKeyboardHookLL (); winRemoveKeyboardHookLL ();
if (!wParam)
/* Revert the X focus as well, but only if the Windows focus is going to another window */ /* Revert the X focus as well, but only if the Windows focus is going to another window */
DeleteWindowFromAnyEvents(pWin, FALSE); if (!wParam && pWin)
DeleteWindowFromAnyEvents(pWin, FALSE);
return 0; return 0;
case WM_SYSDEADCHAR: case WM_SYSDEADCHAR: