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

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