File 0001-kcmultidialog-Fix-crash-in-clear.patch of Package kcmutils.17770
From 89c36527108b031eeb5678d759b701eac7f9dca2 Mon Sep 17 00:00:00 2001
From: Nicolas Fella <nicolas.fella@gmx.de>
Date: Thu, 12 May 2022 03:32:10 +0200
Subject: [PATCH] [kcmultidialog] Fix crash in clear()
The KCModuleProxy is parented into the widget hierarchy and thus deleted when the page is removed
Remove manual delete to avoid a double delete
---
autotests/CMakeLists.txt | 2 ++
autotests/fakekcm/CMakeLists.txt | 3 +++
autotests/fakekcm/fakekcm.cpp | 17 +++++++++++++++++
autotests/kcmultidialogtest.cpp | 29 +++++++++++++++++++++++++++++
src/kcmultidialog.cpp | 1 -
5 files changed, 51 insertions(+), 1 deletion(-)
create mode 100644 autotests/fakekcm/CMakeLists.txt
create mode 100644 autotests/fakekcm/fakekcm.cpp
create mode 100644 autotests/kcmultidialogtest.cpp
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index b0119211..0fa88b33 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -4,6 +4,7 @@ if(NOT EXCLUDE_DEPRECATED_BEFORE_AND_AT STREQUAL "CURRENT" AND
EXCLUDE_DEPRECATED_BEFORE_AND_AT VERSION_LESS 5.88.0)
ecm_add_tests(
kcmoduleinfotest.cpp
+ kcmultidialogtest.cpp
LINK_LIBRARIES KF5KCMUtils Qt${QT_MAJOR_VERSION}::Test
)
@@ -12,3 +13,4 @@ endif()
add_subdirectory(jsonplugin)
add_subdirectory(desktopfilekcm)
add_subdirectory(module_data_codegen)
+add_subdirectory(fakekcm)
diff --git a/autotests/fakekcm/CMakeLists.txt b/autotests/fakekcm/CMakeLists.txt
new file mode 100644
index 00000000..78d10a87
--- /dev/null
+++ b/autotests/fakekcm/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_library(fakekcm MODULE fakekcm.cpp)
+
+target_link_libraries(fakekcm PRIVATE KF5::ConfigWidgets KF5::CoreAddons)
diff --git a/autotests/fakekcm/fakekcm.cpp b/autotests/fakekcm/fakekcm.cpp
new file mode 100644
index 00000000..1630d054
--- /dev/null
+++ b/autotests/fakekcm/fakekcm.cpp
@@ -0,0 +1,17 @@
+/*
+ This file is part of the KDE Frameworks
+ SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de>
+
+ SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
+*/
+
+#include <KCModule>
+#include <KPluginFactory>
+
+class FakeKcm : public KCModule
+{
+};
+
+K_PLUGIN_FACTORY(KCModuleFactory, registerPlugin<KCModule>();)
+
+#include "fakekcm.moc"
diff --git a/autotests/kcmultidialogtest.cpp b/autotests/kcmultidialogtest.cpp
new file mode 100644
index 00000000..4f1e83a5
--- /dev/null
+++ b/autotests/kcmultidialogtest.cpp
@@ -0,0 +1,29 @@
+/*
+ This file is part of the KDE Frameworks
+ SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de>
+
+ SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
+*/
+
+#include <KCMultiDialog>
+
+#include <QObject>
+#include <QTest>
+
+class KCMultiDialogTest : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void testClear();
+};
+
+void KCMultiDialogTest::testClear()
+{
+ KCMultiDialog dialog;
+ dialog.addModule(KPluginMetaData(QStringLiteral("fakekcm")));
+ // Just verify that it doesn't crash
+ dialog.clear();
+}
+
+QTEST_MAIN(KCMultiDialogTest)
+#include "kcmultidialogtest.moc"
diff --git a/src/kcmultidialog.cpp b/src/kcmultidialog.cpp
index edbed5f0..e95bf57d 100644
--- a/src/kcmultidialog.cpp
+++ b/src/kcmultidialog.cpp
@@ -680,7 +680,6 @@ void KCMultiDialog::clear()
for (int i = 0; i < d->modules.count(); ++i) {
removePage(d->modules[i].item);
- delete d->modules[i].kcm;
}
d->modules.clear();
--
GitLab