Skip to content

Commit

Permalink
evdevtouch: Avoid crashing on exit
Browse files Browse the repository at this point in the history
26238ac causes double deletion of the
QTouchDevice in case the post routine already cleaned up the list by the
time the touch handler gets to do it.

Just check the list of devices to see if the one we hold is still there.
If not, the pointer is likely to be a dangling one so do nothing.

This will avoid dying with bus error or similar on application exit.

Task-number: QTBUG-51562
Change-Id: I50c1edee7405aad308274538219698388c2cc9f9
Reviewed-by: Shawn Rutledge <[email protected]>
  • Loading branch information
alpqr committed Aug 10, 2016
1 parent 89d7c90 commit c6cfa22
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/gui/kernel/qwindowsysteminterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ void QWindowSystemInterface::unregisterTouchDevice(const QTouchDevice *device)
QTouchDevicePrivate::unregisterDevice(device);
}

bool QWindowSystemInterface::isTouchDeviceRegistered(const QTouchDevice *device)
{
return QTouchDevicePrivate::isRegistered(device);
}

void QWindowSystemInterface::handleTouchEvent(QWindow *w, QTouchDevice *device,
const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
{
Expand Down
1 change: 1 addition & 0 deletions src/gui/kernel/qwindowsysteminterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Q_GUI_EXPORT QWindowSystemInterface

static void registerTouchDevice(const QTouchDevice *device);
static void unregisterTouchDevice(const QTouchDevice *device);
static bool isTouchDeviceRegistered(const QTouchDevice *device);
static void handleTouchEvent(QWindow *w, QTouchDevice *device,
const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier);
static void handleTouchEvent(QWindow *w, ulong timestamp, QTouchDevice *device,
Expand Down
8 changes: 6 additions & 2 deletions src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,13 @@ void QEvdevTouchScreenHandler::unregisterTouchDevice()
if (!m_device)
return;

QWindowSystemInterface::unregisterTouchDevice(m_device);
// At app exit the cleanup may have already been done, avoid
// double delete by checking the list first.
if (QWindowSystemInterface::isTouchDeviceRegistered(m_device)) {
QWindowSystemInterface::unregisterTouchDevice(m_device);
delete m_device;
}

delete m_device;
m_device = Q_NULLPTR;
}

Expand Down

0 comments on commit c6cfa22

Please sign in to comment.