This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Stop regexp-to-pv assignemnt from leaking
authorFather Chrysostomos <sprout@cpan.org>
Sun, 28 Oct 2012 21:41:55 +0000 (14:41 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 28 Oct 2012 21:41:55 +0000 (14:41 -0700)
SvPV_set will just set SvPVX, allowing the existing value to leak.

This leak was caused by f082678508, which allowed reg_temp_copy to
be called with an existing SV, but without modifying the contents of
reg_temp_copy to account.

regcomp.c

index f676645..d524a99 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -14188,6 +14188,7 @@ Perl_reg_temp_copy (pTHX_ REGEXP *ret_x, REGEXP *rx)
        by pointing directly at the buffer, but flagging that the allocated
        space in the copy is zero. As we've just done a struct copy, it's now
        a case of zero-ing that, rather than copying the current length.  */
+    if (SvPOKp(ret_x)) SvPV_free(ret_x);
     SvPV_set(ret_x, RX_WRAPPED(rx));
     SvFLAGS(ret_x) |= SvFLAGS(rx) & (SVf_POK|SVp_POK|SVf_UTF8);
     memcpy(&(ret->xpv_cur), &(r->xpv_cur),