Skip to content

Commit e531053

Browse files
committed
pp_subst: SV_COW_DROP_PV can leave the sv as the owner of the PV
This was causing leaks in a slightly different version of sv_setsv_cow(), I wasn't able to make it leak in the current version, but this may save someone else's sanity in the future, alas for my own. The rr tool was handy in tracking this down.
1 parent bb003d7 commit e531053

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pp_hot.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5586,11 +5586,15 @@ PP(pp_subst)
55865586
only for us to throw it away here during the substitution. */
55875587
if (SvIsCOW(TARG)) {
55885588
sv_force_normal_flags(TARG, SV_COW_DROP_PV);
5589-
} else
5590-
#endif
5591-
{
5592-
SvPV_free(TARG);
55935589
}
5590+
#endif
5591+
/* If TARG is COW and is the last owner of the buffer
5592+
COW_DROP_PV will remove the COW, leaving TARG as the
5593+
owner, so we may still need to free the PV even if this
5594+
was COW.
5595+
*/
5596+
SvPV_free(TARG);
5597+
55945598
SvPV_set(TARG, SvPVX(dstr));
55955599
SvCUR_set(TARG, SvCUR(dstr));
55965600
SvLEN_set(TARG, SvLEN(dstr));

0 commit comments

Comments
 (0)