summaryrefslogtreecommitdiff
path: root/t/op/attrs.t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-10-10 22:30:18 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-10-10 22:31:38 -0700
commitfb834abdeb17d8cf13dd7590edf8842a8be6e8d7 (patch)
treecd35b9e9da6782503560245540e56921ef623488 /t/op/attrs.t
parent7a776c5a2a628b85aa74437f49111c0a28ff2ff1 (diff)
downloadperl-fb834abdeb17d8cf13dd7590edf8842a8be6e8d7.tar.gz
Stop attribute errors from leaking op trees
This commit moves attribute handling in newATTRSUB so that it happens after the op tree is attached to the sub. So when the sub is freed, the op tree goes with it, instead af leaking when an attribute han- dler dies. Witness what happens without that: $ PERL_DESTRUCT_LEVEL=2 ./perl -Ilib -le 'BEGIN {$^H{a}="b"}; sub foo:bar{1}' Invalid CODE attribute: bar at -e line 1 BEGIN failed--compilation aborted at -e line 1. Unbalanced string table refcount: (1) for "a" at (null) line 1 during global destruction. It was the ‘Unbalanced string table’ warnings that alerted me to the problem. The fairly new t/uni/attrs.t happens to trigger this bug. Not that this told me anything, but I did a binary search which lead me to this commit: commit b3ca2e834c3607fd8aa8736a51aa3a2b8bba1044 Author: Nicholas Clark <nick@ccl4.org> Date: Fri Mar 31 13:45:57 2006 +0000 Serialise changes to %^H onto the current COP. Return the compile time state of %^H as an eleventh value from caller. This allows users to write pragmas. That commit started indirectly storing HEKs in cops (in the hints hash), which means we have an easy way to tell when ops are leaking.
Diffstat (limited to 't/op/attrs.t')
-rw-r--r--t/op/attrs.t7
1 files changed, 7 insertions, 0 deletions
diff --git a/t/op/attrs.t b/t/op/attrs.t
index 339e5da48c..f3d1165e60 100644
--- a/t/op/attrs.t
+++ b/t/op/attrs.t
@@ -366,4 +366,11 @@ foreach my $test (@tests) {
is $w, "", 'no -lvalue warnings under no warnings misc';
}
+unlike runperl(
+ prog => 'BEGIN {$^H{a}=b} sub foo:bar{1}',
+ stderr => 1,
+ ),
+ qr/Unbalanced/,
+ 'attribute errors do not cause op trees to leak';
+
done_testing();