This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix leak in cloned regexes.
When a regex is cloned for a new thread, the string buffer (which holds
the text of the original pattern) wasn't being freed because SvLEN was
being set to 0.
For example:
use threads;
my $r = qr/abc/;
threads->new( sub { 1; })->join;
In the new thread, $r is cloned but when the thread exits, the string
buffer holding "(?^:abc)" was leaking.
This was broken by v5.27.2-30-gdf6b4bd565.
The problem was that in the cloned SV, the buffer was copied, but the
SvLEN(sv) was left set at zero, which along with the SVf_FAKE, mader it
look like the buffer was alien and so not freed.
SvLEN was 0 in the parent thread's $r, since $r and its compile-time
prototype share the same string buffer (so only the original SV has
SvLEN > 0 - all the copies - within the same thread - have mother_re
pointing to the original).
When REs are cloned into another thread, mother_re isn't preserved,
so each RE has its own copy of the buffer.