This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #133959] Free BSD broken tests
authorKarl Williamson <khw@cpan.org>
Wed, 27 Mar 2019 16:28:21 +0000 (10:28 -0600)
committerKarl Williamson <khw@cpan.org>
Wed, 27 Mar 2019 17:13:28 +0000 (11:13 -0600)
Commit 70bd6bc82ba64c1d197d3ec823f43c4a454b2920 fixed a leak (likely due
to a bug in glibc) by not duplicating the C locale object.  However,
that meant that there's only one copy running around.  And freeing that
will cause havoc, as its supposed to be there until destruction.  What
appears to be happening is that the current locale object is freed upon
thread destruction, and that could be this global one.  But I don't
understand why it's only happening on Free BSD and only on this version.
But this commit fixes the problem there, and makes sense.  Simply don't
free this global object upon thread destruction.

This commit also changes it so it doesn't get destroyed at destruction
time, leaving it to the final PERL_SYS_TERM to free.  I'm not sure, but
I think this fixes any issues with embedded perls.

locale.c
perl.c

index 8e440cb..89dc07f 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -5606,7 +5606,7 @@ Perl_thread_locale_term()
 
     {   /* Free up */
         locale_t cur_obj = uselocale(LC_GLOBAL_LOCALE);
 
     {   /* Free up */
         locale_t cur_obj = uselocale(LC_GLOBAL_LOCALE);
-        if (cur_obj != LC_GLOBAL_LOCALE) {
+        if (cur_obj != LC_GLOBAL_LOCALE && cur_obj != PL_C_locale_obj) {
             freelocale(cur_obj);
         }
     }
             freelocale(cur_obj);
         }
     }
diff --git a/perl.c b/perl.c
index 1ef425b..f2de479 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -1153,7 +1153,11 @@ perl_destruct(pTHXx)
         /* This also makes sure we aren't using a locale object that gets freed
          * below */
         const locale_t old_locale = uselocale(LC_GLOBAL_LOCALE);
         /* This also makes sure we aren't using a locale object that gets freed
          * below */
         const locale_t old_locale = uselocale(LC_GLOBAL_LOCALE);
-        if (old_locale != LC_GLOBAL_LOCALE) {
+        if (   old_locale != LC_GLOBAL_LOCALE
+#  ifdef USE_POSIX_2008_LOCALE
+            && old_locale != PL_C_locale_obj
+#  endif
+        ) {
             DEBUG_Lv(PerlIO_printf(Perl_debug_log,
                      "%s:%d: Freeing %p\n", __FILE__, __LINE__, old_locale));
             freelocale(old_locale);
             DEBUG_Lv(PerlIO_printf(Perl_debug_log,
                      "%s:%d: Freeing %p\n", __FILE__, __LINE__, old_locale));
             freelocale(old_locale);