From d2446ddf873ea1aaa5e74d83fa41a7a1e30ce19a Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Thu, 16 Oct 2014 15:28:52 +0100 Subject: [PATCH] wrap XmuClientWindow's XGetWindowProperty in Tk_CreateErrorHandler to fix a rare but persistent BadWindow crash seen on (Lenny, Lucid) Gnome desktop often after closing another application event sequence: ClientMessage: serial=42280 send_event=1 win=0x1 mtype=atom#275 fmt=32 data=0x120 0x2d044 0x1 0x0 0x0 XmuClientWindow(win 0x1) ClientWin.c:65: XGetWindowProperty for atom#311 'WM_STATE' of 0x1 on :0.0 [Last=42282, next=42283] atom#275 is WM_PROTOCOLS without the patch, ClientWin.c:65 will provoke an error e.g. X Error of failed request: BadWindow (invalid Window parameter) Major opcode of failed request: 20 (X_GetProperty) Resource id in failed request: 0x1 Serial number of failed request: 1586296 Current serial number in output stream: 1586296 --- pTk/mTk/additions/ClientWin.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/pTk/mTk/additions/ClientWin.c b/pTk/mTk/additions/ClientWin.c index 89b33f09..bd4ce3b3 100644 --- a/pTk/mTk/additions/ClientWin.c +++ b/pTk/mTk/additions/ClientWin.c @@ -29,6 +29,7 @@ in this Software without prior written authorization from the X Consortium. #include #include +#include "tkInt.h" static Window TryChildren(); @@ -47,17 +48,30 @@ Window XmuClientWindow (dpy, win) unsigned long nitems, after; unsigned char *data; Window inf; + Tk_ErrorHandler handler; WM_STATE = XInternAtom(dpy, "WM_STATE", True); if (!WM_STATE) return win; + + /* + * Ignore X errors when reading the property. + * Sometimes (difficult to reproduce) we were called for a + * ClientMessage{window=0x1}. + */ + + handler = Tk_CreateErrorHandler(dpy, -1, -1, -1, (Tk_ErrorProc *) NULL, (ClientData) NULL); XGetWindowProperty(dpy, win, WM_STATE, 0, 0, False, AnyPropertyType, &type, &format, &nitems, &after, &data); - if (type) - return win; - inf = TryChildren(dpy, win, WM_STATE); - if (!inf) + if (type) { inf = win; + } else { + inf = TryChildren(dpy, win, WM_STATE); + if (!inf) + inf = win; + } + + Tk_DeleteErrorHandler(handler); return inf; #endif }