From c57d487d9b4a96e7e6757056a69af49cbef99318 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 28 Mar 2025 09:40:44 +0100 Subject: [PATCH] tst_QGraphicsWidget: fix memleak in shortcutsDeletion() The QGraphicsWidget didn't have a parent, and wasn't deleted by the test function, so it leaked. To fix, hold it in unique_ptr. While we're at it, and so that it doesn't look too out of place, also hold the other parent-less QGraphicsWidget in a unique_ptr. The action, OTOH, has a parent, so we don't need to change something there. Amends the start of the public history. Pick-to: 6.8 6.5 5.15 Change-Id: I0597b7ecd293ac54981df9e276c38c385ac811c7 Reviewed-by: Axel Spoerl (cherry picked from commit 92c1413c087c5435858f10c0e0c878bc25211b8f) Reviewed-by: Qt Cherry-pick Bot --- .../graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp index 9478eb50bcc..a5841c1882c 100644 --- a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp @@ -2567,16 +2567,16 @@ void tst_QGraphicsWidget::windowFlags() void tst_QGraphicsWidget::shortcutsDeletion() { - QGraphicsWidget *widget = new QGraphicsWidget; - QGraphicsWidget *widget2 = new QGraphicsWidget; + auto widget = std::make_unique(); + const auto widget2 = std::make_unique(); widget->setMinimumSize(40, 40); - QWidgetAction *del = new QWidgetAction(widget); + QWidgetAction *del = new QWidgetAction(widget.get()); del->setIcon(QIcon("edit-delete")); del->setShortcut(Qt::Key_Delete); del->setShortcutContext(Qt::WidgetShortcut); widget2->addAction(del); widget2->addAction(del); - delete widget; + widget.reset(); } class MessUpPainterWidget : public QGraphicsWidget