Index: generic/tkError.c
==================================================================
--- generic/tkError.c
+++ generic/tkError.c
@@ -80,12 +80,12 @@
     Tk_ErrorProc *errorProc,	/* Procedure to invoke when a matching error
 				 * occurs. NULL means just ignore matching
 				 * errors. */
     ClientData clientData)	/* Arbitrary value to pass to errorProc. */
 {
-    register TkErrorHandler *errorPtr;
-    register TkDisplay *dispPtr;
+    TkErrorHandler *errorPtr;
+    TkDisplay *dispPtr;
 
     /*
      * Find the display. If Tk doesn't know about this display then it's an
      * error: panic.
      */
@@ -145,12 +145,12 @@
 void
 Tk_DeleteErrorHandler(
     Tk_ErrorHandler handler)	/* Token for handler to delete; was previous
 				 * return value from Tk_CreateErrorHandler. */
 {
-    register TkErrorHandler *errorPtr = (TkErrorHandler *) handler;
-    register TkDisplay *dispPtr = errorPtr->dispPtr;
+    TkErrorHandler *errorPtr = (TkErrorHandler *) handler;
+    TkDisplay *dispPtr = errorPtr->dispPtr;
 
     errorPtr->lastRequest = NextRequest(dispPtr->display) - 1;
 
     /*
      * Every once-in-a-while, cleanup handlers that are no longer active. We
@@ -164,16 +164,24 @@
      * there are many handlers that stay around forever).
      */
 
     dispPtr->deleteCount += 1;
     if (dispPtr->deleteCount >= 10) {
-	register TkErrorHandler *prevPtr;
+	TkErrorHandler *prevPtr;
 	TkErrorHandler *nextPtr;
-	int lastSerial;
+	int lastSerial = LastKnownRequestProcessed(dispPtr->display);
+
+	/*
+	 * Last chance to catch errors for this handler: if no event/error
+	 * processing took place to follow up the end of this error handler
+	 * we need a round trip with the X server now.
+	 */
 
+	if (errorPtr->lastRequest > (unsigned long) lastSerial) {
+	    XSync(dispPtr->display, False);
+	}
 	dispPtr->deleteCount = 0;
-	lastSerial = LastKnownRequestProcessed(dispPtr->display);
 	errorPtr = dispPtr->errorPtr;
 	for (prevPtr = NULL; errorPtr != NULL; errorPtr = nextPtr) {
 	    nextPtr = errorPtr->nextPtr;
 	    if ((errorPtr->lastRequest != (unsigned long) -1)
 		    && (errorPtr->lastRequest <= (unsigned long) lastSerial)) {
@@ -211,15 +219,15 @@
  */
 
 static int
 ErrorProc(
     Display *display,		/* Display for which error occurred. */
-    register XErrorEvent *errEventPtr)
+    XErrorEvent *errEventPtr)
 				/* Information about error. */
 {
-    register TkDisplay *dispPtr;
-    register TkErrorHandler *errorPtr;
+    TkDisplay *dispPtr;
+    TkErrorHandler *errorPtr;
 
     /*
      * See if we know anything about the display. If not, then invoke the
      * default error handler.
      */

