From 13c5c81cfa934c9b610720fe79e07465b00ebc8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 9 Jan 2012 09:50:08 +0100 Subject: [PATCH] Lock X display while calling XESetWireToEvent and its callback. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevent potential race conditions as suggested by Uli Schlachter. Change-Id: Ia93eb8be1cbbc3d8ae7913a934c195af6b5ec538 Reviewed-by: Jørgen Lind Reviewed-by: Robin Burchell Reviewed-by: Uli Schlachter --- src/plugins/platforms/xcb/qxcbconnection.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index ed995fd8cd..8501af15d3 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -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