fix COW match capture optimisation
authorDavid Mitchell <davem@iabyn.com>
Sat, 20 Jul 2013 15:16:10 +0000 (16:16 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sun, 28 Jul 2013 09:33:40 +0000 (10:33 +0100)
commit5411a0e56ca69f51e1eeaf89ee0a73dcbcf05fb9
tree2db7c978f7f6723602d17d520328a013a8e7de89
parent63a3746a9fd4390177c052a5873163bc11fa8f69
fix COW match capture optimisation

When an SV matches, a new SV is created which is a COW copy of the original
SV, and stored in prog->saved_copy, then prog->subbeg is set to point to
the (shared) PVX buffer.

Earlier in this branch I introduced an optimisation that skipped freeing
the old saved_copy and creating a new COW SV each time, if the old
saved_copy SV was already a shared copy of the SV being matched.

So far so good, except that I implemented it wrongly: if non-COW
matches (which malloc() subbeg) are interspersed with COW matches,
then the subbeg of the COW and the malloced subbeg get mixed up and
AddressSanitizer throws a wobbly.

The fix is simple: in the optimised branch, we still need to free subbeg
if RXp_MATCH_COPIED is true, then reassign it.
regexec.c
t/re/pat.t