From e01e848df4519e8ab9755da41188abdede5b0fb8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 16 Jun 2019 16:51:18 +0200 Subject: [PATCH] QMimeType: towards re-entrancy: do not cache iconName made from mimetype name To not write into a shared object without mutex protection. If the stored icon name is empty, just calculate a new one on each call. Task-number: QTBUG-45684 Change-Id: I01dfb6697b5275e69451da91fdc7346f40bc424e Reviewed-by: David Faure --- src/corelib/mimetypes/qmimetype.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp index b60ff8e9df..de450c68f4 100644 --- a/src/corelib/mimetypes/qmimetype.cpp +++ b/src/corelib/mimetypes/qmimetype.cpp @@ -311,6 +311,14 @@ QString QMimeType::genericIconName() const return d->genericIconName; } +static QString make_default_icon_name_from_mimetype_name(QString iconName) +{ + const int slashindex = iconName.indexOf(QLatin1Char('/')); + if (slashindex != -1) + iconName[slashindex] = QLatin1Char('-'); + return iconName; +} + /*! \property QMimeType::iconName \brief the file name of an icon image that represents the MIME type @@ -324,12 +332,7 @@ QString QMimeType::iconName() const { QMimeDatabasePrivate::instance()->loadIcon(const_cast(*d)); if (d->iconName.isEmpty()) { - // Make default icon name from the mimetype name - QString iconName = name(); - const int slashindex = iconName.indexOf(QLatin1Char('/')); - if (slashindex != -1) - iconName[slashindex] = QLatin1Char('-'); - const_cast(this)->d->iconName = std::move(iconName); + return make_default_icon_name_from_mimetype_name(name()); } return d->iconName; }