Guard against QWindow being deleted during close event

The QBoolBlocker would end up using a stale d-pointer if the window
was deleted during delivery of the close event.

Fixes: QTBUG-102327
Pick-to: 6.3 6.2
Change-Id: I8f458581eeabf0d0f27a348ad1f926295caa3a58
Reviewed-by: Dimitrios Apostolou <jimis@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Tor Arne Vestbø 2022-04-07 19:18:19 +02:00
parent c366d57594
commit 9ab06e6185

View File

@ -2272,8 +2272,15 @@ bool QWindow::close()
if (!d->platformWindow)
return true;
QBoolBlocker inCloseReset(d->inClose);
return d->platformWindow->close();
// The window might be deleted during close,
// as a result of delivering the close event.
QPointer guard(this);
d->inClose = true;
bool success = d->platformWindow->close();
if (guard)
d->inClose = false;
return success;
}
bool QWindowPrivate::participatesInLastWindowClosed() const