Fix handling exceptions in a global destruction

This commit is contained in:
Petr Písař 2020-08-27 14:01:31 +02:00
parent e6a0a682a2
commit 2b720e24e2
2 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,55 @@
From 042abef72d40ab7ff39127e2afae6e34dfc66404 Mon Sep 17 00:00:00 2001
From: Nicolas R <atoomic@cpan.org>
Date: Fri, 14 Aug 2020 16:16:22 -0500
Subject: [PATCH] die_unwind(): global destruction
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Fix #18063
During global destruction make sure we preserve
the string by using mortalcopy.
This is an update on 8c86f0238ecb5f32c2e7fba36e3edfdb54069068
change which avoided sv_mortalcopy in favor of sv_2mortal.
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
pp_ctl.c | 6 +++++-
t/op/die_unwind.t | 4 ++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/pp_ctl.c b/pp_ctl.c
index b8cd869ee0..cc244d7ba7 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1716,7 +1716,11 @@ Perl_die_unwind(pTHX_ SV *msv)
* when unlocalising a tied var). So we do a dance with
* mortalising and SAVEFREEing.
*/
- sv_2mortal(SvREFCNT_inc_simple_NN(exceptsv));
+ if (PL_phase == PERL_PHASE_DESTRUCT) {
+ exceptsv = sv_mortalcopy(exceptsv);
+ } else {
+ exceptsv = sv_2mortal(SvREFCNT_inc_simple_NN(exceptsv));
+ }
/*
* Historically, perl used to set ERRSV ($@) early in the die
diff --git a/t/op/die_unwind.t b/t/op/die_unwind.t
index eee1ce534b..4b83ee6fac 100644
--- a/t/op/die_unwind.t
+++ b/t/op/die_unwind.t
@@ -69,4 +69,8 @@ is($uerr, "t3\n");
is($val, undef, "undefined return value from 'eval' block with 'die'");
is($err, "t3\n");
+fresh_perl_like(<<'EOS', qr/Custom Message During Global Destruction/, { switches => ['-w'], stderr => 1 } );
+package Foo; sub DESTROY { die "Custom Message During Global Destruction" }; package main; our $wut = bless [], "Foo"
+EOS
+
done_testing();
--
2.25.4

View File

@ -229,6 +229,10 @@ Patch32: perl-5.33.0-list-assign-in-list-context-honour-LHS-undef.patch
# in upstream after 5.33.0 # in upstream after 5.33.0
Patch33: perl-5.33.0-Fix-leak-GH-18054.patch Patch33: perl-5.33.0-Fix-leak-GH-18054.patch
# Fix handling exceptions in a global destruction, GH#18063,
# in upstream after 5.33.1
Patch34: perl-5.33.1-die_unwind-global-destruction.patch
# Link XS modules to libperl.so with EU::CBuilder on Linux, bug #960048 # 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 Patch200: perl-5.16.3-Link-XS-modules-to-libperl.so-with-EU-CBuilder-on-Li.patch
@ -4249,6 +4253,7 @@ you're not running VMS, this module does nothing.
%patch31 -p1 %patch31 -p1
%patch32 -p1 %patch32 -p1
%patch33 -p1 %patch33 -p1
%patch34 -p1
%patch200 -p1 %patch200 -p1
%patch201 -p1 %patch201 -p1
@ -4289,6 +4294,7 @@ perl -x patchlevel.h \
'Fedora Patch31: Fix a misoptimization when assignig a list in a list context (GH#17816)' \ 'Fedora Patch31: Fix a misoptimization when assignig a list in a list context (GH#17816)' \
'Fedora Patch32: Fix handling left-hand-side undef when assigning a list (GH#16685)' \ 'Fedora Patch32: Fix handling left-hand-side undef when assigning a list (GH#16685)' \
'Fedora Patch33: Fix a memory leak when compiling a long regular expression (GH#18054)' \ 'Fedora Patch33: Fix a memory leak when compiling a long regular expression (GH#18054)' \
'Fedora Patch34: Fix handling exceptions in a global destruction (GH#18063)' \
'Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on Linux' \ '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' \ 'Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux' \
%{nil} %{nil}
@ -7007,6 +7013,7 @@ popd
- Fix a misoptimization when assignig a list in a list context (GH#17816) - Fix a misoptimization when assignig a list in a list context (GH#17816)
- Fix handling left-hand-side undef when assigning a list (GH#16685) - Fix handling left-hand-side undef when assigning a list (GH#16685)
- Fix a memory leak when compiling a long regular expression (GH#18054) - Fix a memory leak when compiling a long regular expression (GH#18054)
- Fix handling exceptions in a global destruction (GH#18063)
* Fri Aug 21 2020 Jeff Law <law@redhat.com> - 4:5.32.0-461 * Fri Aug 21 2020 Jeff Law <law@redhat.com> - 4:5.32.0-461
- Re-enable LTO - Re-enable LTO