This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make POSIX::mblen() slightly safer
[perl5.git] / ext / POSIX / POSIX.xs
index 27051c1..2972c6d 100644 (file)
@@ -3332,7 +3332,12 @@ mblen(s, n)
         memset(&ps, 0, sizeof(ps)); /* Initialize state */
         RETVAL = mbrlen(s, n, &ps); /* Prefer reentrant version */
 #else
+        /* This might prevent some races, but locales can be switched out
+         * without locking, so this isn't a cure all */
+        LOCALE_LOCK;
+
         RETVAL = mblen(s, n);
+        LOCALE_UNLOCK;
 #endif
     OUTPUT:
         RETVAL