From 23357e59bb4dc54e76a237b290aa64a620db2ea1 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Wed, 2 Apr 2025 15:41:21 +0200 Subject: [PATCH] QMainWindowLayout: Fix leaking of unused tab bars QMainWindowLayout::unusedTabBars contains unparented tab bars. They are leaked when QMainWindow and its layout get destroyed. They still are in QApplication::allWidgets(), which attempts to delete them eventually. When that happens, they try to remove themselves from an already deleted QMainWindowLayout::unusedTabBars. Delete all unused tab bars in the d'tor of QMainWindowLayout. Task-number: QTBUG-135468 Pick-to: 6.9 6.8 6.5 Change-Id: I5ac7748ef738955522567db585e9505e3ba435ad Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qmainwindowlayout.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 6658c24a547..9291fbf240c 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -2726,6 +2726,11 @@ QMainWindowLayout::~QMainWindowLayout() layoutState.deleteCentralWidgetItem(); delete statusbar; + + // unusedTabBars contains unparented tab bars, which need to be removed manually. + // ~QMainWindowTabBar() removes the barĀ from unusedTabBars => call qDeleteAll() on a copy. + const auto bars = unusedTabBars; + qDeleteAll(bars); } void QMainWindowLayout::setDockOptions(QMainWindow::DockOptions opts)