This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #113812] Handle null CvOUTSIDE in cv_clone
authorFather Chrysostomos <sprout@cpan.org>
Tue, 26 Jun 2012 16:23:06 +0000 (09:23 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 26 Jun 2012 16:23:06 +0000 (09:23 -0700)
commit0f9db002b9f34078759729fa70bd1d6fb2350fb8
treec9a1a34cf1ebc9081cd325e1b16f36c69b3fee10
parent0421bbaac46a223a26370e5607f294edc7e77c98
[perl #113812] Handle null CvOUTSIDE in cv_clone

Commit a0d2bbd stopped closures from hanging on to their
enclosing subs.

This means that the outer sub can be freed before the closure.  Since
it is only the outer sub that references the closure prototype (in a
'&' entry in its pad), when the outer sub is freed the closure proto-
type goes with it.  Now if that closure itself contains a closure
(more precisely, a closure prototype in its pad, referenced by an
anoncode op), that inner closure prototype’s CvOUTSIDE points to the
first closure prototype.  When that first closure prototype is freed
the innermost closure prototype has its CvOUTSIDE set to whatever the
outermost sub’s CvOUTSIDE was set to, which could be null if it is
in its own file.  So when the first closure is called, it passes to
cv_clone a closure prototype with no CvOUTSIDE.

cv_clone used to crash if CvOUTSIDE was null.

Example:
$ cat foo.pl

# the main CV of the file is the outer sub in this case
my $x
$first_closure = sub {
    $inner_closure = sub { $x }
}
$ perl -e 'require "./foo.pl"; $first_closure->()'
Bus error

This commit makes it use find_runcv when CvOUTSIDE is null.
MANIFEST
pad.c
t/op/closure.t
t/op/closure_test.pl [new file with mode: 0644]