From f0a9b5b6f11dc5deaabadce0ee672530683cf0a0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 28 Mar 2025 09:31:01 +0100 Subject: [PATCH] tst_QGraphicsWidget: fix memleak in setStyle() The result of QStyleFactory::create() is owned by the caller, and this test function neglected to delete it, leaking the object. To fix, reset() it, once created, into a unique_ptr. This is the minimally0-invasive fix. Amends 9bc49b0bca361646aac90cd00706588d3dcd66c9. Pick-to: 6.9 6.8 6.5 5.15 Change-Id: I17fae174b93bd27e2cac6e5e2d2c8a4ac2de703e Reviewed-by: Axel Spoerl --- .../graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp index bf957fce109..9478eb50bcc 100644 --- a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp @@ -1356,9 +1356,12 @@ void tst_QGraphicsWidget::setStyle() int oldEventCounts = widget.eventCount; + std::unique_ptr reaper; + QFETCH(QString, style); if (!style.isEmpty()) { QStyle *fstyle = QStyleFactory::create(style); + reaper.reset(fstyle); widget.setStyle(fstyle); QCOMPARE(widget.style(), fstyle); } else {