This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
POSIX.xs: Add mutex around localeconv()
authorKarl Williamson <khw@cpan.org>
Wed, 17 Jan 2018 18:22:02 +0000 (11:22 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 31 Jan 2018 13:57:50 +0000 (06:57 -0700)
If another thread calls localeconv(), it can destroy the returned
buffer.  This adds a mutex around this call; the only other place in the
core that calls it already has this mutex, so they now are thread-safe.

ext/POSIX/POSIX.xs

index 7d481c4..0ab9470 100644 (file)
@@ -2145,6 +2145,8 @@ localeconv()
        RETVAL = newHV();
        sv_2mortal((SV*)RETVAL);
 
+        LOCALE_LOCK;    /* Prevent interference with other threads using
+                           localeconv() */
         lcbuf = localeconv();
 
        if (lcbuf) {
@@ -2198,6 +2200,7 @@ localeconv()
             }
        }
 
+        LOCALE_UNLOCK;
         RESTORE_LC_NUMERIC();
 #endif  /* HAS_LOCALECONV */
     OUTPUT: