From 7eb11df19e0c0c52b877bc9ded357763bc014316 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 23 Feb 2017 15:49:38 +0100 Subject: Don't call releaseKey a second time if the insertion fails When the insertion into the cache fails then it will delete the entry for us which already calls releaseKey(). So we should not call it a second time. Task-number: QTBUG-58259 Change-Id: I816c6f29ef97fe3a245f145c4faf1e0649f72dc5 Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Friedemann Kleint --- src/gui/image/qpixmapcache.cpp | 7 ------- tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp | 11 +++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp index 73448943e1..625e145647 100644 --- a/src/gui/image/qpixmapcache.cpp +++ b/src/gui/image/qpixmapcache.cpp @@ -341,7 +341,6 @@ bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost) } else { //Insertion failed we released the new allocated key cacheKeys.remove(key); - releaseKey(cacheKey); } return success; } @@ -355,9 +354,6 @@ QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost) theid = startTimer(flush_time); t = false; } - } else { - //Insertion failed we released the key and return an invalid one - releaseKey(cacheKey); } return cacheKey; } @@ -377,9 +373,6 @@ bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int t = false; } const_cast(key) = cacheKey; - } else { - //Insertion failed we released the key - releaseKey(cacheKey); } return success; } diff --git a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp index 8dcf104035..8a2a35f86c 100644 --- a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp +++ b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp @@ -56,6 +56,7 @@ private slots: void pixmapKey(); void noLeak(); void strictCacheLimit(); + void noCrashOnLargeInsert(); }; static QPixmapCache::KeyData* getPrivate(QPixmapCache::Key &key) @@ -525,5 +526,15 @@ void tst_QPixmapCache::strictCacheLimit() QVERIFY(QPixmapCache::totalUsed() <= limit); } +void tst_QPixmapCache::noCrashOnLargeInsert() +{ + QPixmapCache::clear(); + QPixmapCache::setCacheLimit(100); + QPixmap pixmap(500, 500); + pixmap.fill(Qt::transparent); + QPixmapCache::insert("test", pixmap); + QVERIFY(true); // no crash +} + QTEST_MAIN(tst_QPixmapCache) #include "tst_qpixmapcache.moc" -- cgit v1.2.3