This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_return(): handle dounwind() freeing args
authorDavid Mitchell <davem@iabyn.com>
Tue, 25 Aug 2015 12:57:55 +0000 (13:57 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Feb 2016 08:59:38 +0000 (08:59 +0000)
commit3089a1089dbb3a1c1630ca76dd6db3dc278367e2
treedd0989ddcb80e3449c8855a1daa6d03bc4c8bb0e
parent5b83809469bb55d60f593e77332f17f5a6472a1d
pp_return(): handle dounwind() freeing args

Currently only POPSUB (and other sub-like contexts, such as POPEVAL) do a
LEAVE_SCOPE() as well as restoring things from the context struct. This
means that if pp_return() does a dounwind() to pop back to the next
SUB/EVAL/FORMAT context, LEAVE_SCOPE() won't get called, and any return
values aren't prematurely freed, e.g. in the following

    sub f {
        for (...) {
            my $x = 1;
            return $x;
        }
    }

POPLOOP() won't call LEAVE_SCOPE(), so $x doesn't get freed.

The next commit is about to change that: POPLOOP() will indeed call
LEAVE_SCOPE(), (and later commits may make other POPFOO() types do that
too). So in preparation, this commit makes pp_return() preserve any return
args before calling dounwind().
pp_ctl.c
t/op/sub.t
t/op/sub_lval.t