This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In newATTRSUB, clear glob slot before lowering refcount.
(Actually in its subroutine, S_already_defined.)
Otherwise, when newATTRSUB redefines a sub, the previous sub’s DESTROY
can see the same sub still in the typeglob, but without a reference
count, so *typeglob = sub {} frees the sub currently in $_[0].
$ perl5.18.1 -le '
sub foo{}
bless \&foo;
DESTROY {
print "before: $_[0]"; *foo=sub{}; print "after: $_[0]"
}
eval "sub foo{}";
'
before: main=CODE(0x7fa88382d6d8)
before: main=CODE(0x7fa88382d6d8)
after: main=CODE(0x7fa88382d6d8)
after: UNKNOWN(0x7fa88382d6d8)