From 1110b2c3e4e9c8543aee794b647615977e1c53d8 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Fri, 15 Sep 2023 16:54:04 +0200 Subject: [PATCH] Fix use-after-free error in autotest zwp_primary_selection_device_v1::destroy_func() uses the object after calling zwp_primary_selection_device_v1_destroy_resource(). This means that we cannot do "delete this" at that point. Instead delete all the devices in the destructor of PrimarySelectionDeviceManagerV1, which conveniently already has a list of selection devices. Fixes: QTBUG-117068 Change-Id: I7012f801ef11283d5b66cefbf5481e9f1394f1b8 Reviewed-by: Vlad Zahorodnii Reviewed-by: David Edmundson --- .../primaryselectionv1/tst_primaryselectionv1.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/auto/wayland/primaryselectionv1/tst_primaryselectionv1.cpp b/tests/auto/wayland/primaryselectionv1/tst_primaryselectionv1.cpp index 9e85acca635..d9e4ff295b6 100644 --- a/tests/auto/wayland/primaryselectionv1/tst_primaryselectionv1.cpp +++ b/tests/auto/wayland/primaryselectionv1/tst_primaryselectionv1.cpp @@ -129,11 +129,6 @@ protected: { wl_resource_destroy(resource->handle); } - void zwp_primary_selection_device_v1_destroy_resource(Resource *resource) override - { - Q_UNUSED(resource); - delete this; - } }; class PrimarySelectionDeviceManagerV1 : public Global, public QtWaylandServer::zwp_primary_selection_device_manager_v1 @@ -144,6 +139,10 @@ public: : QtWaylandServer::zwp_primary_selection_device_manager_v1(compositor->m_display, version) , m_version(version) {} + ~PrimarySelectionDeviceManagerV1() override + { + qDeleteAll(m_devices); + } bool isClean() override { for (auto *device : std::as_const(m_devices)) {