From 7c93c29bad5a630df394ef899b8f995cc29154c8 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 17 Aug 2012 14:24:05 -0700 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20leak=20formats=20defined=20insid?= =?utf8?q?e=20subs?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit I made them leak inadvertently in 5.17.2 with commit e09ac076a1da. This was unfortunately backported to 5.16.1 (as 3149499832) without anybody noticing the bug. --- pad.c | 2 +- t/op/write.t | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pad.c b/pad.c index 331922a..d248921 100644 --- a/pad.c +++ b/pad.c @@ -814,7 +814,7 @@ Perl_pad_add_anon(pTHX_ CV* func, I32 optype) if (SvTYPE(func) == SVt_PVCV || !CvOUTSIDE(func)) av_store(PL_comppad, ix, (SV*)func); else { - SV *rv = newRV_inc((SV *)func); + SV *rv = newRV_noinc((SV *)func); sv_rvweaken(rv); assert (SvTYPE(func) == SVt_PVFM); av_store(PL_comppad, ix, rv); diff --git a/t/op/write.t b/t/op/write.t index 5706e49..3fafc20 100644 --- a/t/op/write.t +++ b/t/op/write.t @@ -61,7 +61,7 @@ for my $tref ( @NumTests ){ my $bas_tests = 21; # number of tests in section 3 -my $bug_tests = 8 + 3 * 3 * 5 * 2 * 3 + 2 + 66 + 4 + 2 + 3 + 96 + 10; +my $bug_tests = 8 + 3 * 3 * 5 * 2 * 3 + 2 + 66 + 4 + 2 + 3 + 96 + 11; # number of tests in section 4 my $hmb_tests = 35; @@ -1102,6 +1102,18 @@ write STRICT; close STRICT or die "Could not close: $!"; is cat('Op_write.tmp'), "oof:\n", 'pragmata on format line'; +SKIP: { + skip "no weak refs" unless eval { require Scalar::Util }; + sub Potshriggley { +format Potshriggley = +. + } + Scalar::Util::weaken(my $x = *Potshriggley{FORMAT}); + undef *Potshriggley; + is $x, undef, 'formats in subs do not leak'; + use Devel::Peek; Dump $x if $x; +} + ############################# ## Section 4 -- 2.7.4