diff options
author | Karl Williamson <khw@cpan.org> | 2018-03-19 16:00:21 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2018-03-19 16:27:09 -0600 |
commit | 9fe4122e6defd7e9204ed6f2370d926d4c3b261b (patch) | |
tree | d53ad5ee1c2506b841de59994b06f3ce8d0dc282 /perl.c | |
parent | d15b6e8bb254351ea231a5a70064bbe97568ace7 (diff) | |
download | perl-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.c | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -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) { |