diff options
author | Karl Williamson <khw@cpan.org> | 2022-11-25 10:21:58 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2022-11-29 13:04:42 -0700 |
commit | 67f006ee23a6331e90c3c0429a81e23e0680d8ee (patch) | |
tree | 6e49ab4cf6e5da36e5dfae6526d798ac848bb4bf /locale.c | |
parent | 8ae4238d8389ee011edb8c90e307d8395879c570 (diff) | |
download | perl-67f006ee23a6331e90c3c0429a81e23e0680d8ee.tar.gz |
locale.c: Fix memory leak
PL_C_locale_obj is a global variable, and should be allocated just once
per program. Prior to this commit it could leak under MULTIPLICITY.
I was unable to get LSAN to notice this leak. Tony Cook pointed out
that implementations are likely to use a single static object for this
extremely common scenario. So no leak occurs. Thus this commit only
fixes leaks on implementations using a different method, but does no
harm on the ones that use the static one.
Diffstat (limited to 'locale.c')
-rw-r--r-- | locale.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -4827,7 +4827,9 @@ Perl_init_i18nl10n(pTHX_ int printwarn) # endif # ifdef USE_POSIX_2008_LOCALE - PL_C_locale_obj = newlocale(LC_ALL_MASK, "C", (locale_t) 0); + if (! PL_C_locale_obj) { + PL_C_locale_obj = newlocale(LC_ALL_MASK, "C", (locale_t) 0); + } if (! PL_C_locale_obj) { locale_panic_(Perl_form(aTHX_ "Cannot create POSIX 2008 C locale object")); |