Blame SOURCES/0040-Client-Delay-deletion-of-QDrag-object-until-after-we.patch

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