Utils: Fix theoretical use-after-free

Change-Id: I909f2dcd71c2286036f43fce6fc8aa61c55a6695
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Marcus Tillmanns
2022-10-17 09:54:19 +02:00
parent 2857c73df3
commit 6961790085

View File

@@ -40,7 +40,13 @@ public:
if (!data) {
data = new CachedData;
*data = retrievalFunction(filePath);
m_cache.insert(filePath, data);
if (Q_UNLIKELY(!m_cache.insert(filePath, data))) {
// This path will never happen, but to silence coverity we
// have to check it since insert in theory could delete
// the object if a cost bigger than the cache size is
// specified.
return {};
}
}
// Return a copy of the data, so it cannot be deleted by the cache