In newATTRSUB, clear glob slot before lowering refcount.
authorFather Chrysostomos <sprout@cpan.org>
Mon, 11 Nov 2013 05:41:49 +0000 (21:41 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 12 Nov 2013 00:13:20 +0000 (16:13 -0800)
commita6181857108c5d727c49faec966d4e8d25fae684
tree2fd6aa9c5d6f55e9515801e9d1ac72aec11b9256
parent7004ee4937ce593571fd91b83a7a6e35906e5a05
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)
op.c
t/op/sub.t