From 988ae2e3a2649a5f9e15a68367d4b7f139320c25 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 25 Mar 2025 18:09:09 +0100 Subject: [PATCH] tst_QMenu: fix memleaks in transientParent() QActions and QMenus can be added to several widgets, so addAction() and addMenu() don't transfer ownership of their argument. Having no (QObject) parents, the QMenu and QAction objects in this test were consequently leaked. Fix by giving them parents. Amends 493a85a9e468874471057910a61e7c54a45eee83. Pick-to: 6.8 6.5 Change-Id: I2c48a55de26c5ed487d2e42e50e0b2fbb6ddf98c Reviewed-by: Friedemann Kleint (cherry picked from commit 850d352111d618539d5659e139cfae9f2124fc3c) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index 490947fd825..a18a7a017f7 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -1597,12 +1597,12 @@ void tst_QMenu::transientParent() window.menuBar()->setNativeMenuBar(false); centerOnScreen(&window); - QMenu *fileMenu = new QMenu("&File"); - QAction *exitAct = new QAction("Exit"); + QMenu *fileMenu = new QMenu("&File", &window); + QAction *exitAct = new QAction("Exit", &window); fileMenu->addAction(exitAct); - QMenu *editMenu = new QMenu("&Edit"); - QAction *undoAct = new QAction("Undo"); + QMenu *editMenu = new QMenu("&Edit", &window); + QAction *undoAct = new QAction("Undo", &window); editMenu->addAction(undoAct); QMenuBar *menuBar = new QMenuBar;