Lock X display while calling XESetWireToEvent and its callback.

Prevent potential race conditions as suggested by Uli Schlachter.

Change-Id: Ia93eb8be1cbbc3d8ae7913a934c195af6b5ec538
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Reviewed-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Samuel Rødal 2012-01-09 09:50:08 +01:00 committed by Qt by Nokia
parent b6a43cfe9c
commit 13c5c81cfa

View File

@ -570,13 +570,17 @@ void QXcbConnection::handleXcbEvent(xcb_generic_event_t *event)
if (!handled) {
// Check if a custom XEvent constructor was registered in xlib for this event type, and call it discarding the constructed XEvent if any.
// XESetWireToEvent might be used by libraries to intercept messages from the X server e.g. the OpenGL lib waiting for DRI2 events.
Bool (*proc)(Display*, XEvent*, xEvent*) = XESetWireToEvent((Display*)m_xlib_display, response_type, 0);
Display *xdisplay = (Display *)m_xlib_display;
XLockDisplay(xdisplay);
Bool (*proc)(Display*, XEvent*, xEvent*) = XESetWireToEvent(xdisplay, response_type, 0);
if (proc) {
XESetWireToEvent((Display*)m_xlib_display, response_type, proc);
XESetWireToEvent(xdisplay, response_type, proc);
XEvent dummy;
event->sequence = LastKnownRequestProcessed(m_xlib_display);
proc((Display*)m_xlib_display, &dummy, (xEvent*)event);
proc(xdisplay, &dummy, (xEvent*)event);
}
XUnlockDisplay(xdisplay);
}
#endif