This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
av_fetch(): remove check for freed SV
authorDavid Mitchell <davem@iabyn.com>
Fri, 19 Aug 2016 10:39:20 +0000 (11:39 +0100)
committerDavid Mitchell <davem@iabyn.com>
Fri, 19 Aug 2016 10:44:58 +0000 (11:44 +0100)
commit9fb994be1361ac6bc42256ee6a710159cf050ca5
treec4abfcbf9c9750a49ec2ecd789db2cb56556c83e
parent7c2833f3712a18fc511622f4d27d71a3ce8a3907
av_fetch(): remove check for freed SV

Currently av_fetch() has this extra test:

    if (AvREIFY(av) && SvIS_FREED(AvARRAY(av)[key])) {
        /* eg. @_ could have freed elts */
        AvARRAY(av)[key] = NULL;        /* 1/2 reify */

which basically says that if the array has the reify flag set (typically
only @_ has this) and if the element being retrieved in it has been freed,
then replace it with an undef value instead.

This can be triggered with code like:

    sub f {
        $r = 0;
        my $var = $_[0];
    }

    $r = do { my $x; \$x };
    f($$r);

which leaves $var as undef rather than causing a "panic: attempt to copy
freed scalar".

However, code like

    my ($var) = @_;

*won't* get handled specially, and will still trigger the panic.

It was added in 1996 as a result of this thread:

    From: Andreas Koenig <k@anna.in-berlin.de>
    Subject: SEGV with $_[0] and circular references
    Message-Id: <199608131528.RAA25965@anna.in-berlin.de>

That was in the context of getting a SEGV - whereas now we get the
"panic: attempt to copy freed scalar" instead.

It was agreed in this thread that it could be removed:

    http://nntp.perl.org/group/perl.perl5.porters/239082
av.c
pp_hot.c