Index: unix/tkUnixColor.c
==================================================================
--- unix/tkUnixColor.c
+++ unix/tkUnixColor.c
@@ -92,10 +92,11 @@
 
 	handler = Tk_CreateErrorHandler(DisplayOfScreen(screen),
 		-1, -1, -1, NULL, NULL);
 	XFreeColors(DisplayOfScreen(screen), tkColPtr->colormap,
 		&tkColPtr->color.pixel, 1, 0L);
+	XSync(DisplayOfScreen(screen), False);
 	Tk_DeleteErrorHandler(handler);
     }
     DeleteStressedCmap(DisplayOfScreen(screen), tkColPtr->colormap);
 }
 

Index: unix/tkUnixEmbed.c
==================================================================
--- unix/tkUnixEmbed.c
+++ unix/tkUnixEmbed.c
@@ -470,10 +470,11 @@
 	 * The embedded application is gone. Destroy the container window.
 	 */
 
 	Tk_DestroyWindow((Tk_Window) winPtr);
     }
+    XSync(eventPtr->xfocus.display, False);
     Tk_DeleteErrorHandler(errHandler);
 }
 
 /*
  *----------------------------------------------------------------------
@@ -513,10 +514,11 @@
 		    -1, -1, NULL, NULL);
 	    XMoveResizeWindow(eventPtr->xconfigure.display,
 		    containerPtr->wrapper, 0, 0,
 		    (unsigned) Tk_Width((Tk_Window) containerPtr->parentPtr),
 		    (unsigned) Tk_Height((Tk_Window) containerPtr->parentPtr));
+	    XSync(eventPtr->xfocus.display, False);
 	    Tk_DeleteErrorHandler(errHandler);
 	}
     } else if (eventPtr->type == DestroyNotify) {
 	EmbedWindowDeleted(containerPtr->parentPtr);
     }
@@ -562,10 +564,11 @@
 	if (containerPtr->wrapper != None) {
 	    errHandler = Tk_CreateErrorHandler(eventPtr->xfocus.display, -1,
 		    -1, -1, NULL, NULL);
 	    XSetInputFocus(display, containerPtr->wrapper, RevertToParent,
 		    CurrentTime);
+	    XSync(eventPtr->xfocus.display, False);
 	    Tk_DeleteErrorHandler(errHandler);
 	}
     }
 }
 

Index: unix/tkUnixFocus.c
==================================================================
--- unix/tkUnixFocus.c
+++ unix/tkUnixFocus.c
@@ -110,10 +110,11 @@
     if (winPtr->window == None) {
 	Tcl_Panic("ChangeXFocus got null X window");
     }
     XSetInputFocus(dispPtr->display, winPtr->window, RevertToParent,
 	    CurrentTime);
+    XSync(dispPtr->display, False);
     Tk_DeleteErrorHandler(errHandler);
 
     /*
      * Remember the current serial number for the X server and issue a dummy
      * server request. This marks the position at which we changed the focus,

Index: unix/tkUnixRFont.c
==================================================================
--- unix/tkUnixRFont.c
+++ unix/tkUnixRFont.c
@@ -386,10 +386,11 @@
 	XUnloadFont(fontPtr->display, fontPtr->font.fid);
     }
     if (fontPtr->fontset) {
 	FcFontSetDestroy(fontPtr->fontset);
     }
+    XSync(display, False);
     Tk_DeleteErrorHandler(handler);
 }
 
 TkFont *
 TkpGetNativeFont(
@@ -873,10 +874,11 @@
     } else {
 	Tk_ErrorHandler handler =
 		Tk_CreateErrorHandler(display, -1, -1, -1, NULL, NULL);
 
 	XftDrawChange(fontPtr->ftDraw, drawable);
+	XSync(display, False);
 	Tk_DeleteErrorHandler(handler);
     }
     XGetGCValues(display, gc, GCForeground, &values);
     xftcolor = LookUpColor(display, fontPtr, values.foreground);
     if (tsdPtr->clipRegion != None) {
@@ -1006,10 +1008,11 @@
     } else {
 	Tk_ErrorHandler handler =
 		Tk_CreateErrorHandler(display, -1, -1, -1, NULL, NULL);
 
 	XftDrawChange(fontPtr->ftDraw, drawable);
+	XSync(display, False);
 	Tk_DeleteErrorHandler(handler);
     }
 
     XGetGCValues(display, gc, GCForeground, &values);
     xftcolor = LookUpColor(display, fontPtr, values.foreground);
@@ -1095,10 +1098,11 @@
     } else {
 	Tk_ErrorHandler handler =
 		Tk_CreateErrorHandler(display, -1, -1, -1, NULL, NULL);
 
 	XftDrawChange(fontPtr->ftDraw, drawable);
+	XSync(display, False);
 	Tk_DeleteErrorHandler(handler);
     }
     XGetGCValues(display, gc, GCForeground, &values);
     xftcolor = LookUpColor(display, fontPtr, values.foreground);
     if (tsdPtr->clipRegion != None) {

Index: unix/tkUnixSelect.c
==================================================================
--- unix/tkUnixSelect.c
+++ unix/tkUnixSelect.c
@@ -468,10 +468,11 @@
 			(unsigned char *) propPtr, numItems);
 		if (propPtr != NULL) {
 		    ckfree(propPtr);
 		}
 	    }
+	    XSync(eventPtr->xproperty.display, False);
 	    Tk_DeleteErrorHandler(errorHandler);
 
 	    /*
 	     * Compute the next offset value. If this was the last chunk, then
 	     * set the offset to -2. If this was an empty chunk, then set the
@@ -1046,10 +1047,11 @@
 	 */
 
 	reply.xsel.property = incr.multAtoms[1];
     }
     XSendEvent(reply.xsel.display, reply.xsel.requestor, False, 0, &reply.ev);
+    XSync(reply.xsel.display, False);
     Tk_DeleteErrorHandler(errorHandler);
 
     /*
      * Handle any remaining INCR-mode transfers. This all happens in callbacks
      * to TkSelPropProc, so just wait until the number of uncompleted INCR
@@ -1064,10 +1066,11 @@
 	}
 	Tcl_DeleteTimerHandler(incr.timeout);
 	errorHandler = Tk_CreateErrorHandler(winPtr->display,
 		-1, -1, -1, (int (*)()) NULL, NULL);
 	XSelectInput(reply.xsel.display, reply.xsel.requestor, 0L);
+	XSync(winPtr->display, False);
 	Tk_DeleteErrorHandler(errorHandler);
 	if (tsdPtr->pendingIncrs == &incr) {
 	    tsdPtr->pendingIncrs = incr.nextPtr;
 	} else {
 	    for (incrPtr2 = tsdPtr->pendingIncrs; incrPtr2 != NULL;

Index: unix/tkUnixSend.c
==================================================================
--- unix/tkUnixSend.c
+++ unix/tkUnixSend.c
@@ -1746,10 +1746,11 @@
 
     handler = Tk_CreateErrorHandler(display, -1, -1, -1, AppendErrorProc,
 	    pendingPtr);
     XChangeProperty(display, window, property, XA_STRING, 8,
 	    PropModeAppend, (unsigned char *) value, length);
+    XSync(display, False);
     Tk_DeleteErrorHandler(handler);
 }
 
 /*
  * The function below is invoked if an error occurs during the XChangeProperty

Index: unix/tkUnixWm.c
==================================================================
--- unix/tkUnixWm.c
+++ unix/tkUnixWm.c
@@ -4082,10 +4082,11 @@
 
     handler = Tk_CreateErrorHandler(winPtr->display, -1, -1, -1, NULL, NULL);
     XMoveResizeWindow(winPtr->display, winPtr->window, 0,
 	    wmPtr->menuHeight, (unsigned) wrapperPtr->changes.width,
 	    (unsigned) (wrapperPtr->changes.height - wmPtr->menuHeight));
+    XSync(winPtr->display, False);
     Tk_DeleteErrorHandler(handler);
     if ((wmPtr->menubar != NULL)
 	    && ((Tk_Width(wmPtr->menubar) != wrapperPtr->changes.width)
 	    || (Tk_Height(wmPtr->menubar) != wmPtr->menuHeight))) {
 	Tk_MoveResizeWindow(wmPtr->menubar, 0, 0, wrapperPtr->changes.width,
@@ -4418,14 +4419,15 @@
 	     * manager). This is probably not a good thing, but cleanup as
 	     * best we can. The error handler is needed because
 	     * Tk_DestroyWindow will try to destroy the window, but of course
 	     * it's already gone.
 	     */
+	    Display *display = wmPtr->winPtr->display;
 
-	    handler = Tk_CreateErrorHandler(wmPtr->winPtr->display, -1, -1, -1,
-		    NULL, NULL);
+	    handler = Tk_CreateErrorHandler(display, -1, -1, -1, NULL, NULL);
 	    Tk_DestroyWindow((Tk_Window) wmPtr->winPtr);
+	    XSync(display, False);
 	    Tk_DeleteErrorHandler(handler);
 	}
 	if (dispPtr->flags & TK_DISPLAY_WM_TRACING) {
 	    printf("TopLevelEventProc: %s deleted\n", wmPtr->winPtr->pathName);
 	}
@@ -5844,14 +5846,16 @@
 	    /*
 	     * We can end up here when the window is in the middle of being
 	     * deleted
 	     */
 
+	    XSync(Tk_Display(tkwin), False);
 	    Tk_DeleteErrorHandler(handler);
 	    return NULL;
 	}
 	if (child == None) {
+	    XSync(Tk_Display(tkwin), False);
 	    Tk_DeleteErrorHandler(handler);
 	    return NULL;
 	}
 	for (wmPtr = (WmInfo *) dispPtr->firstWmPtr; wmPtr != NULL;
 		wmPtr = wmPtr->nextPtr) {
@@ -5877,10 +5881,11 @@
 	/*
 	 * Check value of handler, because we can reach this label from above
 	 * or below
 	 */
 
+	XSync(Tk_Display(tkwin), False);
 	Tk_DeleteErrorHandler(handler);
 	handler = NULL;
     }
     winPtr = wmPtr->winPtr;
     if (winPtr->mainPtr != ((TkWindow *) tkwin)->mainPtr) {

