This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #114888] Localise PL_comppad_name in cv_clone
In 9ef8d56 I made closures share their pad name lists, and not just
the names themselves, for speed (no need to SvREFCNT_inc each name and
copy the list).
To make that work, I had to set PL_comppad_name in cv_clone, before
the pad_new call. But I failed to move the PL_comppad_name localisa-
tion from pad_new to cv_clone.
So cv_clone would merrily clobber the previous value of
PL_comppad_name *before* localising it.
This only manifested itself in source filters. Most of the time,
pp_anoncode is called at run time when either no code is being com-
piled (PL_comppad_name is only used at compile time) or inside a
BEGIN block which itself localises PL_comppad_name. But inside a
Filter::Util::Call source filter there was no buffer like that to
protect it.
This meant that pad name creation (my $x) would create the name in the
PL_comppad_name belonging to the last-cloned sub. A subsequent name
lookup ($x) would look in the correct place, as it uses the moral
equivalent of PadlistNAMES(CvPADLIST(PL_compcv)), not PL_comppad_name.
So it would not find it, resulting in a global variable or a stricture
violation.