From 573c39ff002175f58b9f5ede8ccd1502e3f1b51d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 27 Mar 2025 09:34:11 +0100 Subject: [PATCH] tst_QSplitter: fix memleak in replaceWidgetWhileHidden() QSplitter::replaceWidget() is decumented to un-parent and return the original widget (the one that the newWidget) replaces, so the caller of the function is responsible for deleting it, which the test function neglected. Fix by storing the returned object in a unique_ptr for delayed deletion at the exit of the function. This is the minimally-invasive change. Amends fb56a0f2ce34e95d955095c01ecf2943046be85e. Pick-to: 6.8 6.5 Change-Id: Ia63ebfde59b1c5ef8ddb6c3f3ab10b28d5bf6cff Reviewed-by: Axel Spoerl (cherry picked from commit f9d9630e9ec4963b779ed98b9fc50ac03c9156d6) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp index 071e6d4cbce..465df2c1f49 100644 --- a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp +++ b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp @@ -861,7 +861,7 @@ void tst_QSplitter::replaceWidgetWhileHidden() newWidget->hide(); const bool wasExplicitHide = !widgetVisible && newWidget->testAttribute(Qt::WA_WState_ExplicitShowHide); - splitter.replaceWidget(1, newWidget); + const std::unique_ptr reaper{splitter.replaceWidget(1, newWidget)}; QCOMPARE(!widgetVisible && newWidget->testAttribute(Qt::WA_WState_ExplicitShowHide), wasExplicitHide);