Skip to content

Commit

Permalink
locale.c: Critical section around initializing a global
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
khwilliamson committed May 6, 2023
1 parent 52eb9b8 commit 862164e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion locale.c
Expand Up @@ -7112,12 +7112,19 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
# endif
# ifdef USE_POSIX_2008_LOCALE

if (! PL_C_locale_obj) {
/* This is a global, so be sure to keep another instance from zapping it */
LOCALE_LOCK;
if (PL_C_locale_obj) {
LOCALE_UNLOCK;
}
else {
PL_C_locale_obj = newlocale(LC_ALL_MASK, "C", (locale_t) 0);
if (! PL_C_locale_obj) {
LOCALE_UNLOCK;
locale_panic_(Perl_form(aTHX_
"Cannot create POSIX 2008 C locale object"));
}
LOCALE_UNLOCK;

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

0 comments on commit 862164e

Please sign in to comment.