Skip to content

Commit 79c6bd0

Browse files
committed
locale.c: Critical section around initializing a global
This code should only have a race in the unlikely event that it is an embedded perl, and there is another perl already running. But best to avoid the possibility at all.
1 parent 433aa97 commit 79c6bd0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

locale.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6335,12 +6335,19 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
63356335
# endif
63366336
# ifdef USE_POSIX_2008_LOCALE
63376337

6338-
if (! PL_C_locale_obj) {
6338+
/* This is a global, so be sure to keep another instance from zapping it */
6339+
LOCALE_LOCK;
6340+
if (PL_C_locale_obj) {
6341+
LOCALE_UNLOCK;
6342+
}
6343+
else {
63396344
PL_C_locale_obj = newlocale(LC_ALL_MASK, "C", (locale_t) 0);
63406345
if (! PL_C_locale_obj) {
6346+
LOCALE_UNLOCK;
63416347
locale_panic_(Perl_form(aTHX_
63426348
"Cannot create POSIX 2008 C locale object"));
63436349
}
6350+
LOCALE_UNLOCK;
63446351

63456352
DEBUG_Lv(PerlIO_printf(Perl_debug_log, "created C object %p\n",
63466353
PL_C_locale_obj));

0 commit comments

Comments
 (0)