Client: Delay deletion of QDrag object until after we're done with it

In certain cases, most notably when performing drag and drop operations
with touch, the QDrag object gets deleted before data_source_send is
executed. This then tries to access a deleted data_source, crashing the
client.

To avoid this, we indicate we want the QDrag object to stay around and
then delete it in QWaylandDrag::finishDrag, which with data_device v3 is
guaranteed to be called after everyone is done with the data source.

Change-Id: I6a2f5a219f58d1b721a9fec33c57d26d2c522ec9
Reviewed-by: David Edmundson <davidedmundson@kde.org>
This commit is contained in:
Arjen Hiemstra 2021-11-18 13:05:30 +01:00
parent 3bf9a581ee
commit 18df960499
2 changed files with 12 additions and 0 deletions

View File

@ -80,6 +80,9 @@ void QWaylandDrag::cancel()
QBasicDrag::cancel();
m_display->currentInputDevice()->dataDevice()->cancelDrag();
if (drag())
drag()->deleteLater();
}
void QWaylandDrag::move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
@ -130,6 +133,14 @@ void QWaylandDrag::finishDrag()
{
QKeyEvent event(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier);
eventFilter(shapedPixmapWindow(), &event);
if (drag())
drag()->deleteLater();
}
bool QWaylandDrag::ownsDragObject() const
{
return true;
}
}

View File

@ -83,6 +83,7 @@ protected:
void drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
void endDrag() override;
bool ownsDragObject() const override;
private:
QWaylandDisplay *m_display = nullptr;