This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid leak assigning regexp to non-COW string
authorDavid Mitchell <davem@iabyn.com>
Fri, 22 Mar 2019 17:38:48 +0000 (17:38 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 25 Mar 2019 12:35:27 +0000 (12:35 +0000)
commit1385ac98c5f75358978bb05c2d6c4134413cf689
treefcd6f9aede4b279d3702630b258122981f017bc1
parent803bd7c91c63f8f263bed592a33b10cf69f567cf
avoid leak assigning regexp to non-COW string

In something like

    $s = substr(.....); # $s now a non-COW SvPOK() SV
    $r = qr/..../;
    $s = $$r;

$s's previous string buffer would leak when an SVt_REGEXP type SV is
assigned to it.

Worse, if $s was an SVt_PVPV, it would fail an assert on debugging
builds.

The fix is to make sure any remaining stringy stuff is cleaned up
before copying the REGEXP.
regcomp.c
t/op/qr.t