summaryrefslogtreecommitdiff
path: root/perl.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2018-03-19 16:00:21 -0600
committerKarl Williamson <khw@cpan.org>2018-03-19 16:27:09 -0600
commit9fe4122e6defd7e9204ed6f2370d926d4c3b261b (patch)
treed53ad5ee1c2506b841de59994b06f3ce8d0dc282 /perl.c
parentd15b6e8bb254351ea231a5a70064bbe97568ace7 (diff)
downloadperl-9fe4122e6defd7e9204ed6f2370d926d4c3b261b.tar.gz
perl.c: Free some locale stuff on exit
This stops potential memory leaks when using POSIX 2008 locale handling, by freeing the current locale object and two special ones.
Diffstat (limited to 'perl.c')
-rw-r--r--perl.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/perl.c b/perl.c
index 181c597fd2..c6923eb314 100644
--- a/perl.c
+++ b/perl.c
@@ -1154,20 +1154,33 @@ perl_destruct(pTHXx)
PL_curlocales[i] = NULL;
}
#endif
-#ifdef USE_LOCALE_NUMERIC
- Safefree(PL_numeric_name);
- PL_numeric_name = NULL;
- SvREFCNT_dec(PL_numeric_radix_sv);
- PL_numeric_radix_sv = NULL;
-
-# ifdef HAS_POSIX_2008_LOCALE
+#ifdef HAS_POSIX_2008_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) {
+ freelocale(old_locale);
+ }
+ }
+# ifdef USE_LOCALE_NUMERIC
if (PL_underlying_numeric_obj) {
- /* Make sure we aren't using the locale space we are about to free */
- uselocale(LC_GLOBAL_LOCALE);
freelocale(PL_underlying_numeric_obj);
PL_underlying_numeric_obj = (locale_t) NULL;
}
# endif
+# ifdef USE_POSIX_2008_LOCALE
+ if (PL_C_locale_obj) {
+ freelocale(PL_C_locale_obj);
+ PL_C_locale_obj = NULL;
+ }
+# endif
+#endif
+#ifdef USE_LOCALE_NUMERIC
+ Safefree(PL_numeric_name);
+ PL_numeric_name = NULL;
+ SvREFCNT_dec(PL_numeric_radix_sv);
+ PL_numeric_radix_sv = NULL;
#endif
if (PL_setlocale_buf) {