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 <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
bb10
Andy Shaw 2017-02-23 15:49:38 +01:00
parent c0af8cef2f
commit 7eb11df19e
2 changed files with 11 additions and 7 deletions

View File

@ -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<QPixmapCache::Key&>(key) = cacheKey;
} else {
//Insertion failed we released the key
releaseKey(cacheKey);
}
return success;
}

View File

@ -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"