MockCompositor: Protect against race condition

The QList m_fractionalScales was being changed from both the main thread
and the dispatch thread. This lead to read-after-free AddressSanitizer
errors when running autotests. Using a DirectConnection makes sure that
both appending and removal happens in the same thread. This does not
fix a theoretical race condition in DefaultCompositor::fractionalScale().

Fixes: QTBUG-130627
Pick-to: 6.8
Change-Id: Ie73f80d08929bcfcbd9940acdb4f86233df013cb
Reviewed-by: David Edmundson <davidedmundson@kde.org>
This commit is contained in:
Paul Olav Tvete 2024-11-06 17:07:30 +01:00
parent 77aeb195a4
commit 4781e2a088

View File

@ -16,7 +16,7 @@ void FractionalScaleManager::wp_fractional_scale_manager_v1_get_fractional_scale
auto *scaler = new FractionalScale(s, resource->client(), id, resource->version());
connect(scaler, &QObject::destroyed, this, [this, scaler]() {
m_fractionalScales.removeOne(scaler);
});
}, Qt::DirectConnection);
m_fractionalScales << scaler;
}