This is a live mirror of the Perl 5 development currently hosted at
Respect SvLEN==0 and SvOOK in sv.c:sv_sethek
authorFather Chrysostomos <>
Wed, 7 Aug 2013 16:04:20 +0000 (09:04 -0700)
committerFather Chrysostomos <>
Sat, 10 Aug 2013 02:28:33 +0000 (19:28 -0700)
SvLEN==0 means this scalar does not own the buffer, so it should
not free it.

SvOOK means that SvPVX does not point to the start of the buffer
because we have cheated with s/...// or substr and not copied the
string back.

I don’t believe any such scalars currently make their way into
sv_sethek and get past the THINKFIRST check in that state, but we
should still play it safe.

SvPV_free handles both cases.


diff --git a/sv.c b/sv.c
index c28ed7d..283178f 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -4718,7 +4718,7 @@ Perl_sv_sethek(pTHX_ SV *const sv, const HEK *const hek)
            SvUPGRADE(sv, SVt_PV);
-           Safefree(SvPVX(sv));
+           SvPV_free(sv);
            SvPV_set(sv,(char *)HEK_KEY(share_hek_hek(hek)));
            SvCUR_set(sv, HEK_LEN(hek));
            SvLEN_set(sv, 0);