summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-08-17 14:24:05 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-08-17 16:45:22 -0700
commit7c93c29bad5a630df394ef899b8f995cc29154c8 (patch)
tree49c8a226ec7c9247f157fd73d187dff3a5a1c47b
parent84eea98055f218b655619db1600f75f511c33e3d (diff)
downloadperl-7c93c29bad5a630df394ef899b8f995cc29154c8.tar.gz
Don’t leak formats defined inside subs
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.
-rw-r--r--pad.c2
-rw-r--r--t/op/write.t14
2 files changed, 14 insertions, 2 deletions
diff --git a/pad.c b/pad.c
index 331922aef0..d248921612 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 5706e49889..3fafc204ae 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