QMacPasteboard: check QGuiApplication is alive for a promise containing QPixmap

Otherwise, when platform integration is deleted, it triggers resolving
promises after the global instance of QGuiApplication is dead and
QPixmap in turn calls qFatal, crashing the exiting app.

Fixes: QTBUG-106472
Change-Id: Ie706d030214c33abdbc8fff86cc2eddd0c632f1b
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Timur Pocheptsov 2022-09-13 09:01:13 +02:00
parent 88fbbb422e
commit 20d7d41a74
2 changed files with 17 additions and 1 deletions

View File

@ -30,6 +30,12 @@ private:
QPointer<QMacMimeData> mimeData;
QVariant variantData;
DataRequestType dataRequestType;
// QMimeData can be set from QVariant, holding
// QPixmap. When converting, this triggers
// QPixmap's ctor which in turn requires QGuiApplication
// to exist and thus will abort the application
// abnormally if not.
bool isPixmap = false;
};
QList<Promise> promises;

View File

@ -8,6 +8,7 @@
#include <QtGui/qguiapplication.h>
#include <QtGui/qbitmap.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qmetatype.h>
#include <QtCore/qdebug.h>
#include <QtCore/private/qcore_mac_p.h>
#include <QtGui/qguiapplication.h>
@ -57,9 +58,12 @@ QMacPasteboard::Promise::Promise(int itemId, QMacInternalPasteboardMime *c, QStr
// Request the data from the application immediately for eager requests.
if (dataRequestType == QMacPasteboard::EagerRequest) {
variantData = md->variantData(m);
isPixmap = variantData.metaType().id() == QMetaType::QPixmap;
mimeData = nullptr;
} else {
mimeData = md;
if (md->hasImage())
isPixmap = md->imageData().metaType().id() == QMetaType::QPixmap;
}
}
@ -170,8 +174,14 @@ OSStatus QMacPasteboard::promiseKeeper(PasteboardRef paste, PasteboardItemID id,
// to request the data from the application.
QVariant promiseData;
if (promise.dataRequestType == LazyRequest) {
if (!qpaste->resolvingBeforeDestruction && !promise.mimeData.isNull())
if (!qpaste->resolvingBeforeDestruction && !promise.mimeData.isNull()) {
if (promise.isPixmap && !QGuiApplication::instance()) {
qCWarning(lcQpaClipboard,
"Cannot keep promise, data contains QPixmap and requires livining QGuiApplication");
return cantGetFlavorErr;
}
promiseData = promise.mimeData->variantData(promise.mime);
}
} else {
promiseData = promise.variantData;
}