This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Stop anon subs with bad attributes from leaking
authorFather Chrysostomos <sprout@cpan.org>
Tue, 13 Nov 2012 04:10:56 +0000 (20:10 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 13 Nov 2012 08:01:33 +0000 (00:01 -0800)
op.c
t/op/svleak.t

diff --git a/op.c b/op.c
index 8fab398..3f71cff 100644 (file)
--- a/op.c
+++ b/op.c
@@ -7624,7 +7624,9 @@ Perl_newATTRSUB_flags(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
     if (attrs) {
        /* Need to do a C<use attributes $stash_of_cv,\&cv,@attrs>. */
        HV *stash = name && GvSTASH(CvGV(cv)) ? GvSTASH(CvGV(cv)) : PL_curstash;
+       if (!name) SAVEFREESV(cv);
        apply_attrs(stash, MUTABLE_SV(cv), attrs);
+       if (!name) SvREFCNT_inc_simple_void_NN(cv);
     }
 
     if (block && has_name) {
index 16461b9..8134b56 100644 (file)
@@ -15,7 +15,7 @@ BEGIN {
 
 use Config;
 
-plan tests => 63;
+plan tests => 64;
 
 # run some code N times. If the number of SVs at the end of loop N is
 # greater than (N-1)*delta at the end of loop 1, we've got a leak
@@ -194,6 +194,8 @@ SKIP: {
     leak(2, 0, sub { eval q{ my $x = "x"; "abc" =~ /$x/ for 1..5 } }, '#114356');
 }
 
+eleak(2, 0, '+sub:a{}', 'anon subs with invalid attributes');
+
 # Syntax errors
 eleak(2, 0, '"${<<END}"
                  ', 'unterminated here-doc in quotes in multiline eval');