From b15d1ee499f5e5974574f38e8e8dd975cd874c85 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 27 Mar 2025 10:04:22 +0100 Subject: [PATCH] tst_QSplitter: don't leak the QSplitter from initTestCase() Several test functions use a centrally-allocated QSplitter for their tests. This object was allocated in initTestCase(), but cleanTestCase(), while present, was empty, so nothing deleted the object again. Fix by deleting the object in cleanupTestCase(). Initialize the member variable to nullptr so that the delete is well-formed even if initTestCase() for some reason didn't run (or didn't run to completion). Amends the start of the public history, where this function read #if defined(QT3_SUPPORT) delete qApp->mainWidget(); #endif which was already leaking if QT3_SUPPORT wasn't defined. Pick-to: 6.8 6.5 5.15 Change-Id: I43e5d8921a9c097f252e11709f25bc622fc8fe15 Reviewed-by: Axel Spoerl (cherry picked from commit fbaa37633580dcf6b8ec3cd4a0da8d85902de2ea) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp index 5133b22a754..de2c10c0c54 100644 --- a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp +++ b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp @@ -75,7 +75,7 @@ private slots: private: void removeThirdWidget(); void addThirdWidget(); - QSplitter *splitter; + QSplitter *splitter = nullptr; QWidget *w1; QWidget *w2; QWidget *w3; @@ -144,6 +144,7 @@ void tst_QSplitter::addThirdWidget() void tst_QSplitter::cleanupTestCase() { + delete splitter; }