[fix s/// memory leak]
Larry Wall [Tue, 14 Mar 1995 00:43:53 +0000 (16:43 -0800)]
In fixing another bug I installed a nasty memory leak in s///.  Here's the fix.

Larry

pp_ctl.c
pp_hot.c

index cca1fc1..201c32e 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -114,6 +114,7 @@ PP(pp_substcont)
            SV *targ = cx->sb_targ;
            sv_catpvn(dstr, s, cx->sb_strend - s);
 
+           Safefree(SvPVX(targ));
            SvPVX(targ) = SvPVX(dstr);
            SvCUR_set(targ, SvCUR(dstr));
            SvLEN_set(targ, SvLEN(dstr));
index 7bfec4a..dedb217 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1451,6 +1451,7 @@ PP(pp_subst)
            safebase));
        sv_catpvn(dstr, s, strend - s);
 
+       Safefree(SvPVX(TARG));
        SvPVX(TARG) = SvPVX(dstr);
        SvCUR_set(TARG, SvCUR(dstr));
        SvLEN_set(TARG, SvLEN(dstr));