QFileIconEngine: Remove reference to QFileIconProvider

Keeping the reference may end up in a crash if a created
QIcon outlives the QFileIconProvider and we then try to
generate a pixmap.

The reference is not necessary since the options are queried
only when creating the icon, so they can be saved in the icon
provider.

Task-number: QTBUG-46755
Change-Id: I5c60887c2ed39030a2a20298ff10fd652189e4e7
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
This commit is contained in:
Gabriel de Dietrich 2015-06-24 10:31:07 +02:00
parent b0852eb271
commit 52e7aba6bf
2 changed files with 22 additions and 6 deletions

View File

@ -63,8 +63,8 @@ static bool isCacheable(const QFileInfo &fi);
class QFileIconEngine : public QPixmapIconEngine
{
public:
QFileIconEngine(const QFileIconProvider *fip, const QFileInfo &info)
: QPixmapIconEngine(), m_fileIconProvider(fip), m_fileInfo(info)
QFileIconEngine(const QFileInfo &info, QFileIconProvider::Options opts)
: QPixmapIconEngine(), m_fileInfo(info), m_fipOpts(opts)
{ }
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE
@ -90,7 +90,7 @@ public:
}
QPlatformTheme::IconOptions iconOptions;
if (m_fileIconProvider->options() & QFileIconProvider::DontUseCustomDirectoryIcons)
if (m_fipOpts & QFileIconProvider::DontUseCustomDirectoryIcons)
iconOptions |= QPlatformTheme::DontUseCustomDirectoryIcons;
pixmap = theme->fileIconPixmap(m_fileInfo, size, iconOptions);
@ -152,8 +152,8 @@ public:
}
private:
const QFileIconProvider *m_fileIconProvider;
QFileInfo m_fileInfo;
QFileIconProvider::Options m_fipOpts;
};
@ -346,8 +346,7 @@ QIcon QFileIconProviderPrivate::getIcon(const QFileInfo &fi) const
if (sizes.isEmpty())
return QIcon();
Q_Q(const QFileIconProvider);
return QIcon(new QFileIconEngine(q, fi));
return QIcon(new QFileIconEngine(fi, options));
}
/*!

View File

@ -58,6 +58,8 @@ private slots:
void type_data();
void type();
void taskQTBUG_46755_QFileIconEngine_crash();
};
// Subclass that exposes the protected functions.
@ -167,6 +169,21 @@ void tst_QFileIconProvider::type()
QVERIFY(!provider.type(info).isEmpty());
}
static QIcon getIcon()
{
QFileIconProvider fip;
return fip.icon(QDir::currentPath());
}
void tst_QFileIconProvider::taskQTBUG_46755_QFileIconEngine_crash()
{
const QIcon &icon = getIcon();
foreach (const QSize &size, icon.availableSizes())
icon.pixmap(size);
// No crash, all good.
}
QTEST_MAIN(tst_QFileIconProvider)
#include "tst_qfileiconprovider.moc"