From 681e3fe5c15fff964a3ef91ffba8795b59986f63 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 27 Mar 2025 06:48:38 +0100 Subject: [PATCH] tst_QFrame: fix memleak in testPainting() Similar to 5be58ac9271555eed3a2884d827f30c164d2277d for tst_QWidget, this test leaked the result of QStyleFactory::create() and the fix is the same: cache across the test function calls. This time, it's for performance; there's like 50 different data tags for this function... Amends a8723871ee7125b97ce5467b94198e93a528c960. Pick-to: 6.8 6.5 5.15 Change-Id: I95cc1dc4459489904f3a5e0347570eb07ccdfde8 Reviewed-by: Axel Spoerl (cherry picked from commit 44a2d8cc2066a6230bc26d78070e75e3f19c7832) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/widgets/widgets/qframe/tst_qframe.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/auto/widgets/widgets/qframe/tst_qframe.cpp b/tests/auto/widgets/widgets/qframe/tst_qframe.cpp index 324c512219a..d3286fa4c9e 100644 --- a/tests/auto/widgets/widgets/qframe/tst_qframe.cpp +++ b/tests/auto/widgets/widgets/qframe/tst_qframe.cpp @@ -19,6 +19,15 @@ private slots: void testInitStyleOption(); void testPainting_data(); void testPainting(); + +private: + mutable std::unique_ptr m_style; + QStyle *fusionStyle() const + { + if (!m_style) + m_style.reset(QStyleFactory::create(QStringLiteral("fusion"))); + return m_style.get(); + } }; Q_DECLARE_METATYPE(QFrame::Shape) @@ -141,7 +150,7 @@ void tst_QFrame::testPainting() QFETCH(QFrame::Shadow, shadow); QFrame frame; - frame.setStyle(QStyleFactory::create(QStringLiteral("fusion"))); + frame.setStyle(fusionStyle()); frame.setPalette(qt_fusionPalette()); frame.setFrameStyle(shape | shadow); frame.setLineWidth(lineWidth);