[EPS] Fix crash at app shutdown (being tried to persist clipboard image)

Summary:
Deny any capabilities when there is no QApp instance.

BUG: 397040

Test Plan:
Untested, as I do not experience the bug on my system and had no time to
invest into trying to.

Reviewers: zccrs, dfaure, pino

Reviewed By: dfaure

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D15405
This commit is contained in:
Friedrich W. H. Kossebau 2018-09-10 14:49:54 +02:00
parent 167967a145
commit 98c65a438d

View File

@ -14,6 +14,7 @@
#include <QPrinter>
#include <QProcess>
#include <QTemporaryFile>
#include <QCoreApplication>
// logging category for this framework, default: log stuff >= warning
Q_LOGGING_CATEGORY(EPSPLUGIN, "epsplugin", QtWarningMsg)
@ -333,6 +334,15 @@ bool EPSHandler::canRead(QIODevice *device)
QImageIOPlugin::Capabilities EPSPlugin::capabilities(QIODevice *device, const QByteArray &format) const
{
// prevent bug #397040: when on app shutdown the clipboard content is to be copied to survive end of the app,
// QXcbIntegration looks for some QImageIOHandler to apply, querying the capabilities and picking any first.
// At that point this plugin no longer has its requirements e.g. to run the external process, so we have to deny.
// The capabilities seem to be queried on demand in Qt code and not cached, so it's fine to report based
// in current dynamic state
if (!QCoreApplication::instance()) {
return {};
}
if (format == "eps" || format == "epsi" || format == "epsf") {
return Capabilities(CanRead | CanWrite);
}