On Thu, Jun 23, 2005 at 12:12:36PM +0100, Nicholas Clark wrote:
> If you build perl with -DDEBUG_LEAKING_SCALARS and test with
> PERL_DESTRUCT_LEVEL=2 then there are some reads of free memory in S_new_SV
> as it tries to initialise sv->sv_debug_line:
> 
>     sv->sv_debug_line = (U16) ((PL_copline == NOLINE) ?
>         (PL_curcop ? CopLINE(PL_curcop) : 0) : PL_copline);
> 
> ==3147==    at 0x80F1794: S_new_SV (sv.c:238)
> ==3147==    by 0x80FC193: Perl_newSV (sv.c:4864)
> ==3147==    by 0x80AFEF6: Perl_pad_swipe (pad.c:1057)

pad_swipe() frees the current slot of a PADTMP, then replaces it with a
new null SV. This used to make sense when PADTMPs were shared between ops,
but not any more. The change below just sets the slots to PL_sv_undef,
marking them free for reuse.

This avoids a whole bunch of useless calls to new_SV() during global
destruction, and as a side effect, stops valgring compaining.

-- 
Hofstadter's Law:
It always takes longer than you expect, even when you take into account
Hofstadter's Law.

Change 24967 by [EMAIL PROTECTED] on 2005/06/23 22:48:40

        don't repopulate PADTMP slots with null SVs when freeing ops

Affected files ...

... //depot/perl/ext/B/t/f_sort.t#13 edit
... //depot/perl/ext/B/t/optree_samples.t#11 edit
... //depot/perl/pad.c#60 edit

Differences ...

==== //depot/perl/ext/B/t/f_sort.t#13 (text) ====

@@ -104,7 +104,7 @@
 # 7  <0> pushmark s
 # 8  <#> gv[*articles] s
 # 9  <1> rv2av[t2] lKRM*/1
-# a  <2> aassign[t5] KS
+# a  <2> aassign[t3] KS
 # b  <1> leavesub[1 ref] K/REFC,1
 EOT_EOT
 # 1  <;> nextstate(main 546 (eval 15):1) v
@@ -178,7 +178,7 @@
 # 7  <0> pushmark s
 # 8  <#> gv[*articles] s
 # 9  <1> rv2av[t2] lKRM*/1
-# a  <2> aassign[t5] KS
+# a  <2> aassign[t3] KS
 # b  <1> leavesub[1 ref] K/REFC,1
 EOT_EOT
 # 1  <;> nextstate(main 546 (eval 15):1) v
@@ -215,7 +215,7 @@
 # 7  <0> pushmark s
 # 8  <#> gv[*articles] s
 # 9  <1> rv2av[t2] lKRM*/1
-# a  <2> aassign[t5] KS
+# a  <2> aassign[t3] KS
 # b  <1> leavesub[1 ref] K/REFC,1
 EOT_EOT
 # 1  <;> nextstate(main 546 (eval 15):1) v
@@ -252,7 +252,7 @@
 # 7  <0> pushmark s
 # 8  <#> gv[*articles] s
 # 9  <1> rv2av[t2] lKRM*/1
-# a  <2> aassign[t5] KS
+# a  <2> aassign[t3] KS
 # b  <1> leavesub[1 ref] K/REFC,1
 EOT_EOT
 # 1  <;> nextstate(main 546 (eval 15):1) v
@@ -799,7 +799,7 @@
 # d  <0> pushmark s
 # e  <#> gv[*result] s
 # f  <1> rv2av[t2] lKRM*/1
-# g  <2> aassign[t5] KS/COMMON
+# g  <2> aassign[t3] KS/COMMON
 # h  <1> leavesub[1 ref] K/REFC,1
 EOT_EOT
 # 1  <;> nextstate(main 547 (eval 15):1) v

==== //depot/perl/ext/B/t/optree_samples.t#11 (text) ====

@@ -607,7 +607,7 @@
 # 3  <$> const[AV ] s
 # 4  <1> rv2av lKPM/1
 # 5  <@> mapstart K
-# 6  <|> mapwhile(other->7)[t7] K
+# 6  <|> mapwhile(other->7)[t5] K
 # 7      <#> gvsv[*_] s
 # 8      <$> const[IV 42] s
 # 9      <2> add[t2] sK/2

==== //depot/perl/pad.c#60 (text) ====

@@ -1055,10 +1055,17 @@
     if (refadjust)
        SvREFCNT_dec(PL_curpad[po]);
 
+
+    /* if pad tmps aren't shared between ops, then there's no need to
+     * create a new tmp when an existing op is freed */
+#ifdef USE_BROKEN_PAD_RESET
     PL_curpad[po] = NEWSV(1107,0);
     SvPADTMP_on(PL_curpad[po]);
+#else
+    PL_curpad[po] = &PL_sv_undef;
     if ((I32)po < PL_padix)
        PL_padix = po - 1;
+#endif
 }
 
 

Reply via email to