From 8f28ebb93c29d13d409dbee42e863ff12524cfe5 Mon Sep 17 00:00:00 2001 From: Petr Písař Date: Apr 08 2019 12:50:01 +0000 Subject: Fix a memory leak when spawning threads in a BEGIN phase --- diff --git a/perl-5.29.9-fix-leak-in-BEGIN-threads-new.patch b/perl-5.29.9-fix-leak-in-BEGIN-threads-new.patch new file mode 100644 index 0000000..279c60c --- /dev/null +++ b/perl-5.29.9-fix-leak-in-BEGIN-threads-new.patch @@ -0,0 +1,49 @@ +From 803bd7c91c63f8f263bed592a33b10cf69f567cf Mon Sep 17 00:00:00 2001 +From: David Mitchell +Date: Fri, 22 Mar 2019 15:43:56 +0000 +Subject: [PATCH] fix leak in BEGIN { threads->new(...) } +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Normally by the time we reach perl_destruct(), PL_parser should be null +due to having its original (null) value restored by SAVEt_PARSER during +leaving scope (usually before run-time starts in fact). But if a thread +is created within a BEGIN block, the parser is duped, but the +SAVEt_PARSER savestack entry isn't. So PL_parser never gets cleaned up. +Clean it up in perl_destruct() instead. This is a bit of a hack. + +Signed-off-by: Petr Písař +--- + perl.c | 15 +++++++++++++++ + 1 file changed, 15 insertions(+) + +diff --git a/perl.c b/perl.c +index cdefa99018..1ef425bb25 100644 +--- a/perl.c ++++ b/perl.c +@@ -668,6 +668,21 @@ perl_destruct(pTHXx) + FREETMPS; + assert(PL_scopestack_ix == 0); + ++ /* normally when we get here, PL_parser should be null due to having ++ * its original (null) value restored by SAVEt_PARSER during leaving ++ * scope (usually before run-time starts in fact). ++ * But if a thread is created within a BEGIN block, the parser is ++ * duped, but the SAVEt_PARSER savestack entry isn't. So PL_parser ++ * never gets cleaned up. ++ * Clean it up here instead. This is a bit of a hack. ++ */ ++ if (PL_parser) { ++ /* stop parser_free() stomping on PL_curcop */ ++ PL_parser->saved_curcop = PL_curcop; ++ parser_free(PL_parser); ++ } ++ ++ + /* Need to flush since END blocks can produce output */ + /* flush stdout separately, since we can identify it */ + #ifdef USE_PERLIO +-- +2.20.1 + diff --git a/perl.spec b/perl.spec index 02d0bce..a76e8e8 100644 --- a/perl.spec +++ b/perl.spec @@ -279,6 +279,10 @@ Patch60: perl-5.28.1-Fix-POSIX-mblen-mbstate_t-initialization-on-threaded # Fix a memory leak when cloning a regular expression, in upstream after 5.29.9 Patch61: perl-5.29.9-fix-leak-in-cloned-regexes.patch +# Fix a memory leak when spawning threads in a BEGIN phase, +# in upstream after 5.29.9 +Patch62: perl-5.29.9-fix-leak-in-BEGIN-threads-new.patch + # Link XS modules to libperl.so with EU::CBuilder on Linux, bug #960048 Patch200: perl-5.16.3-Link-XS-modules-to-libperl.so-with-EU-CBuilder-on-Li.patch @@ -2896,6 +2900,7 @@ Perl extension for Version Objects %patch59 -p1 %patch60 -p1 %patch61 -p1 +%patch62 -p1 %patch200 -p1 %patch201 -p1 @@ -2949,6 +2954,7 @@ perl -x patchlevel.h \ 'Fedora Patch59: Fix a buffer overread when parsing a regular expression with an unknown character name (RT#133880)' \ 'Fedora Patch60: Fix mbstate_t initialization in POSIX::mblen (RT#133928)' \ 'Fedora Patch61: Fix a memory leak when cloning a regular expression' \ + 'Fedora Patch62: Fix a memory leak when spawning threads in a BEGIN phase' \ 'Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on Linux' \ 'Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux' \ %{nil} @@ -5245,6 +5251,7 @@ popd character name (RT#133880) - Fix mbstate_t initialization in POSIX::mblen (RT#133928) - Fix a memory leak when cloning a regular expression +- Fix a memory leak when spawning threads in a BEGIN phase * Tue Feb 26 2019 Petr Pisar - 4:5.28.1-429 - Adjust tests to gdbm-1.15 using an upstream fix (RT#133295)