summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2018-02-20 16:04:56 +0100
committerMorten Johan Sørvig <morten.sorvig@qt.io>2018-03-19 14:38:45 +0000
commiteba1d56fad03198098f3eea353c4b42fac3306a7 (patch)
tree76d6d5ca3d5fa47e76c4d1463d295fb4514a4a7c /src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
parentdae8133ded616c9038407793232ae946fcf93e8c (diff)
Cocoa: Fix crash in currentModalSession()
Add null-pointer checks to QCocoaEventDispatcher:: currentModalSession(): - window->handle() may return nullptr if the window has been destroyed. - We call beginModalSessionForWindow, which processes events. This can potentially destroy or delete the current window; pointers to it must be checked again. This also has the effect that currentModalSessionCached is not set to a session that does not have a window, also prevents clearing the cleanupModalSessionsNeeded flag for such sessions. Task-number: QTBUG-66536 Change-Id: Ie055933c872a8ede3c938882fb2d4f7cf8ff3c81 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
index bf9ba4eccf..06978fb3fc 100644
--- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
+++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
@@ -637,6 +637,8 @@ NSModalSession QCocoaEventDispatcherPrivate::currentModalSession()
if (!info.session) {
QMacAutoReleasePool pool;
QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(info.window->handle());
+ if (!cocoaWindow)
+ continue;
NSWindow *nswindow = cocoaWindow->nativeWindow();
if (!nswindow)
continue;
@@ -647,6 +649,15 @@ NSModalSession QCocoaEventDispatcherPrivate::currentModalSession()
[(NSWindow*) info.nswindow retain];
QRect rect = cocoaWindow->geometry();
info.session = [NSApp beginModalSessionForWindow:nswindow];
+
+ // The call to beginModalSessionForWindow above processes events and may
+ // have deleted or destroyed the window. Check if it's still valid.
+ if (!info.window)
+ continue;
+ cocoaWindow = static_cast<QCocoaWindow *>(info.window->handle());
+ if (!cocoaWindow)
+ continue;
+
if (rect != cocoaWindow->geometry())
cocoaWindow->setGeometry(rect);
}