summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2021-09-11 10:11:21 +0000
committerPaul Evans <leonerd@leonerd.org.uk>2021-09-11 13:04:25 +0100
commitc1d304d234269da7c796c3a2df9f816ab377d4ba (patch)
treeb9c31db03dfca0749fc3ec6310f7def94e8b8b68 /sv.c
parente3dd969a9d98d3f8789cc6513a31ed4ca00fa884 (diff)
downloadperl-c1d304d234269da7c796c3a2df9f816ab377d4ba.tar.gz
Fix a leak when copying a STATIC COW SV to a stringified SV
This is minor a a regression introduced by commit 914bb57489325d34: Define a third kind of COW state; STATIC ... sv_setsv_flags() and sv_setsv_cow() will preserve this state There was a small omission in the copy code - it didn't handle the case where the destination SV owned a string buffer already. This is actually relatively rare - triggering it requires a scalar in code path that is assigned both strings and booleans. Minimal test case is: my $got = 1; $got .= ""; $got = ref ""; cut down from &is in t/comp/parser.t
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/sv.c b/sv.c
index 8363dc5d3c..d20cbf2a85 100644
--- a/sv.c
+++ b/sv.c
@@ -4691,6 +4691,9 @@ Perl_sv_setsv_flags(pTHX_ SV *dsv, SV* ssv, const I32 flags)
* SV_COW_SHARED_HASH_KEYS being set or else we'll break SvIsBOOL()
*/
else if (SvIsCOW_static(ssv)) {
+ if (SvPVX_const(dsv)) { /* we know that dtype >= SVt_PV */
+ SvPV_free(dsv);
+ }
SvPV_set(dsv, SvPVX(ssv));
SvLEN_set(dsv, 0);
SvCUR_set(dsv, cur);