summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2010-07-05 20:40:33 +0100
committerDavid Mitchell <davem@iabyn.com>2010-07-14 23:06:17 +0100
commit4c74a7df3242aa95d62dcfbcc231b8a55cc03c59 (patch)
tree40e1d5a912f0d7cfb9868075dda2ee1c5dcfcb7a /t
parente3d2b9e76ba8553f994404cc1438760e83dd8b76 (diff)
downloadperl-4c74a7df3242aa95d62dcfbcc231b8a55cc03c59.tar.gz
protect CvSTASH weakref with backrefs
Each CV usually has a pointer, CvSTASH, back to the stash that it was complied in. This pointer isn't reference counted, to avoid loops. Which can leave it dangling if the stash is deleted. There is already protection for the similar GvSTASH field in GVs: the stash has an array of backrefs, xhv_backreferences, pointing to the GVs whose GvSTASHes point to it, and which is used to zero all the GvSTASH fields should the stash be deleted. All this patch does is also add the CVs with CvSTASH to that stash's backref list too.
Diffstat (limited to 't')
-rw-r--r--t/op/stash.t15
1 files changed, 14 insertions, 1 deletions
diff --git a/t/op/stash.t b/t/op/stash.t
index 8eb50515cf..676c26c8c2 100644
--- a/t/op/stash.t
+++ b/t/op/stash.t
@@ -7,7 +7,7 @@ BEGIN {
BEGIN { require "./test.pl"; }
-plan( tests => 31 );
+plan( tests => 32 );
# Used to segfault (bug #15479)
fresh_perl_like(
@@ -168,4 +168,17 @@ SKIP: {
{},
"no segfault with overload/deleted stash entry [#58530]",
);
+
+ # CvSTASH should be null on a nmed sub if the stash has been deleted
+ {
+ package FOO;
+ sub foo {}
+ my $rfoo = \&foo;
+ package main;
+ delete $::{'FOO::'};
+ my $cv = B::svref_2object($rfoo);
+ # XXX is there a better way of testing for NULL ?
+ my $stash = $cv->STASH;
+ like($stash, qr/B::SPECIAL/, "NULL CvSTASH on named sub");
+ }
}