c0ca8c9
From 7024b57e6b25ea4c666eb665f64cf2cebd2b4905 Mon Sep 17 00:00:00 2001
d8d5f48
From: Arjen Hiemstra <ahiemstra@heimr.nl>
d8d5f48
Date: Thu, 18 Nov 2021 13:05:30 +0100
c0ca8c9
Subject: [PATCH 15/57] Client: Delay deletion of QDrag object until after
d8d5f48
 we're done with it
d8d5f48
d8d5f48
In certain cases, most notably when performing drag and drop operations
d8d5f48
with touch, the QDrag object gets deleted before data_source_send is
d8d5f48
executed. This then tries to access a deleted data_source, crashing the
d8d5f48
client.
d8d5f48
d8d5f48
To avoid this, we indicate we want the QDrag object to stay around and
d8d5f48
then delete it in QWaylandDrag::finishDrag, which with data_device v3 is
d8d5f48
guaranteed to be called after everyone is done with the data source.
d8d5f48
d8d5f48
Change-Id: I6a2f5a219f58d1b721a9fec33c57d26d2c522ec9
d8d5f48
Reviewed-by: David Edmundson <davidedmundson@kde.org>
d8d5f48
(cherry picked from commit 39e3290efa2dd40722fa3322284cae3b01ccedf4)
d8d5f48
---
d8d5f48
 src/client/qwaylanddnd.cpp | 11 +++++++++++
d8d5f48
 src/client/qwaylanddnd_p.h |  1 +
d8d5f48
 2 files changed, 12 insertions(+)
d8d5f48
d8d5f48
diff --git a/src/client/qwaylanddnd.cpp b/src/client/qwaylanddnd.cpp
d8d5f48
index 97ee5b2e..7c53f5fa 100644
d8d5f48
--- a/src/client/qwaylanddnd.cpp
d8d5f48
+++ b/src/client/qwaylanddnd.cpp
d8d5f48
@@ -80,6 +80,9 @@ void QWaylandDrag::cancel()
d8d5f48
     QBasicDrag::cancel();
d8d5f48
 
d8d5f48
     m_display->currentInputDevice()->dataDevice()->cancelDrag();
d8d5f48
+
d8d5f48
+    if (drag())
d8d5f48
+        drag()->deleteLater();
d8d5f48
 }
d8d5f48
 
d8d5f48
 void QWaylandDrag::move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
d8d5f48
@@ -130,6 +133,14 @@ void QWaylandDrag::finishDrag()
d8d5f48
 {
d8d5f48
     QKeyEvent event(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier);
d8d5f48
     eventFilter(shapedPixmapWindow(), &event);
d8d5f48
+
d8d5f48
+    if (drag())
d8d5f48
+        drag()->deleteLater();
d8d5f48
+}
d8d5f48
+
d8d5f48
+bool QWaylandDrag::ownsDragObject() const
d8d5f48
+{
d8d5f48
+    return true;
d8d5f48
 }
d8d5f48
 
d8d5f48
 }
d8d5f48
diff --git a/src/client/qwaylanddnd_p.h b/src/client/qwaylanddnd_p.h
d8d5f48
index 747f0190..46f629ac 100644
d8d5f48
--- a/src/client/qwaylanddnd_p.h
d8d5f48
+++ b/src/client/qwaylanddnd_p.h
d8d5f48
@@ -83,6 +83,7 @@ protected:
d8d5f48
     void drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
d8d5f48
     void endDrag() override;
d8d5f48
 
d8d5f48
+    bool ownsDragObject() const override;
d8d5f48
 
d8d5f48
 private:
d8d5f48
     QWaylandDisplay *m_display = nullptr;
d8d5f48
-- 
c0ca8c9
2.45.1
d8d5f48