ICU: lock the mutex before calling an Unlocked function

The QIcuCodec::defaultCodecUnlocked function is not thread-safe
because it calls codecForNameUnlocked. In turn, that one accesses and
even modifies a QHash stored in the QCoreGlobalData singleton, which
is what makes it non-threadsafe.

In order to call the Unlocked function, we need to lock the mutex
first.

Change-Id: I915570110229f4c0929986aa26731244317ef6ab
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Thiago Macieira 2012-08-03 12:27:28 +02:00 committed by Qt by Nokia
parent 4e542d958a
commit 5566254948

View File

@ -683,7 +683,9 @@ QTextCodec* QTextCodec::codecForLocale()
QTextCodec *codec = globalData->codecForLocale.loadAcquire();
if (!codec) {
#ifdef QT_USE_ICU
textCodecsMutex()->lock();
codec = QIcuCodec::defaultCodecUnlocked();
textCodecsMutex()->unlock();
#else
// setupLocaleMapper locks as necessary
codec = setupLocaleMapper();