Stop my subs with syntax errors from leaking
authorFather Chrysostomos <sprout@cpan.org>
Wed, 14 Nov 2012 07:41:19 +0000 (23:41 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 14 Nov 2012 17:53:46 +0000 (09:53 -0800)
op.c
t/op/svleak.t

diff --git a/op.c b/op.c
index b3ac10d..3480a6c 100644 (file)
--- a/op.c
+++ b/op.c
@@ -6970,6 +6970,8 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
 
     if (PL_parser && PL_parser->error_count) {
        op_free(block);
+       SvREFCNT_dec(PL_compcv);
+       PL_compcv = 0;
        goto done;
     }
 
index 0b4db43..c365709 100644 (file)
@@ -15,7 +15,7 @@ BEGIN {
 
 use Config;
 
-plan tests => 68;
+plan tests => 69;
 
 # 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 @@ eleak(2, 0, 'sub', '"sub" with nothing following');
 eleak(2, 0, '+sub:a{}', 'anon subs with invalid attributes');
 eleak(2, 0, 'no warnings; sub a{1 1}', 'sub with syntax error');
 eleak(2, 0, 'no warnings; sub {1 1}', 'anon sub with syntax error');
+eleak(2, 0, 'no warnings; use feature ":all"; my sub a{1 1}',
+     'my sub with syntax error');
 
 # Syntax errors
 eleak(2, 0, '"${<<END}"