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

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