QCache: Fix crash observed in tst_QAccessibility

Fixes a use-after-free which can reliably be observed under ASAN. In
QConfFileSettingsPrivate::~QConfFileSettingsPrivate we call
unusedCache->insert(conf_file->name, conf_file, ...)
Note that the key is a member of the object. Thus by deleting the object
before using the key, we dereference a dangling pointer.

Amends f08492c6fd.

Change-Id: I3a550fc73446b72dd46456232e85f6d206d64c01
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
(cherry picked from commit 5283ee71040dc2f3a762e9cc5e807fb17587e9b7)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Fabian Kosmale 2020-11-25 21:09:27 +01:00 committed by Qt Cherry-pick Bot
parent d3caea04dc
commit 5abe64928c

View File

@ -237,8 +237,8 @@ public:
bool insert(const Key &key, T *object, qsizetype cost = 1)
{
if (cost > mx) {
delete object;
remove(key);
delete object;
return false;
}
trim(mx - cost);