From 216b9cb080b00c5f477c0ced58c354e5714d5720 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Wed, 18 Nov 2020 17:26:50 +0100 Subject: [PATCH] msvcrt: Lock global locale in _get_current_locale. Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcrt/locale.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index 8afac8aba87..dd9a7ce0930 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -1117,6 +1117,22 @@ void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo) MSVCRT_free(mbcinfo); } +/********************************************************************* + * _lock_locales (UCRTBASE.@) + */ +void CDECL _lock_locales(void) +{ + _mlock(_SETLOCALE_LOCK); +} + +/********************************************************************* + * _unlock_locales (UCRTBASE.@) + */ +void CDECL _unlock_locales(void) +{ + _munlock(_SETLOCALE_LOCK); +} + MSVCRT__locale_t CDECL get_current_locale_noalloc(MSVCRT__locale_t locale) { thread_data_t *data = msvcrt_get_thread_data(); @@ -1124,6 +1140,7 @@ MSVCRT__locale_t CDECL get_current_locale_noalloc(MSVCRT__locale_t locale) if(!data || !data->have_locale) { + _lock_locales(); *locale = *MSVCRT_locale; } else @@ -1144,6 +1161,8 @@ MSVCRT__locale_t CDECL get_current_locale_noalloc(MSVCRT__locale_t locale) if(locale->locinfo->ctype1_refcount) InterlockedIncrement(locale->locinfo->ctype1_refcount); InterlockedIncrement(&locale->locinfo->lc_time_curr->refcount); + if(locale->locinfo == MSVCRT_locale->locinfo) + _unlock_locales(); InterlockedIncrement(&locale->mbcinfo->refcount); return locale; @@ -1930,22 +1949,6 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, return locinfo; } -/********************************************************************* - * _lock_locales (UCRTBASE.@) - */ -void CDECL _lock_locales(void) -{ - _mlock(_SETLOCALE_LOCK); -} - -/********************************************************************* - * _unlock_locales (UCRTBASE.@) - */ -void CDECL _unlock_locales(void) -{ - _munlock(_SETLOCALE_LOCK); -} - /********************************************************************* * _create_locale (MSVCRT.@) */