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.9 6.8 6.5
Change-Id: I2c48a55de26c5ed487d2e42e50e0b2fbb6ddf98c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Marc Mutz 2025-03-25 18:09:09 +01:00
parent 09991b51a4
commit 850d352111

View File

@ -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;