summarylogtreecommitdiffstats
path: root/0027-QMainWindowTabBar-Use-QPointer-for-mainWindow-member.patch
blob: db6a08e005389ff736155cceb027affbf6082d08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
From 1cf945b826a64004bd62bb72945a9878fda29f61 Mon Sep 17 00:00:00 2001
From: Axel Spoerl <axel.spoerl@qt.io>
Date: Tue, 17 Jun 2025 14:01:46 +0200
Subject: [PATCH 27/31] QMainWindowTabBar: Use QPointer for mainWindow member

The member mainWindow is a raw pointer to the QMainWindow.
A QMainWindowTabBar isn't necessarily parented to the QMainWindow, when
it's unused. If the QMainWindow has already been destroyed, the member
may contain a stale pointer.

Use a QPoitner instead, to avoid use after free.

Task-number: QTBUG-137755
Change-Id: I488bfcfd222e5015aec15d8748565e1de1f9adf1
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
(cherry picked from commit 86b46a011c679bb361b51381ff0e281f03284be1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit ca8219583bd31a807b2040bf621e819097902646)
---
 src/widgets/widgets/qmainwindowlayout.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp
index 83626b251a7..f46095abc86 100644
--- a/src/widgets/widgets/qmainwindowlayout.cpp
+++ b/src/widgets/widgets/qmainwindowlayout.cpp
@@ -1893,7 +1893,7 @@ void QMainWindowLayout::keepSize(QDockWidget *w)
 class QMainWindowTabBar : public QTabBar
 {
     Q_OBJECT
-    QMainWindow *mainWindow;
+    QPointer<QMainWindow> mainWindow;
     QPointer<QDockWidget> draggingDock; // Currently dragging (detached) dock widget
 public:
     QMainWindowTabBar(QMainWindow *parent);
-- 
2.50.1