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)
==3147==    by 0x8099756: Perl_op_clear (op.c:346)
==3147==    by 0x80995ED: Perl_op_free (op.c:314)
==3147==    by 0x8099587: Perl_op_free (op.c:302)
==3147==    by 0x8099587: Perl_op_free (op.c:302)
==3147==    by 0x8099587: Perl_op_free (op.c:302)
==3147==    by 0x8099587: Perl_op_free (op.c:302)
==3147==    by 0x8062501: perl_destruct (perl.c:514)
==3147==    by 0x8060485: main (perlmain.c:105)
==3147==  Address 0x3C6120A4 is 40 bytes inside a block of size 52 free'd
==3147==    at 0x3C01E72D: free (vg_replace_malloc.c:127)
==3147==    by 0x80CB726: Perl_safesysfree (util.c:155)
==3147==    by 0x80995FB: Perl_op_free (op.c:315)
==3147==    by 0x8099587: Perl_op_free (op.c:302)
==3147==    by 0x8062501: perl_destruct (perl.c:514)
==3147==    by 0x8060485: main (perlmain.c:105)

This seems to occur in

  lib/Switch/t/given.t
  lib/Switch/t/switch.t
  lib/encoding/warnings/t/1-warning.t
  lib/encoding/warnings/t/2-fatal.t

I've applied the appended change which clears up the two in encoding/warnings,
but only seems to reduce the number of problems in the Switch tests.

Any ideas?

Nicholas Clark

Change 24952 by [EMAIL PROTECTED] on 2005/06/23 10:41:00

        Re-initialise PL_curcop to &PL_compiling before destroying the optree.

Affected files ...

... //depot/perl/perl.c#633 edit

Differences ...

==== //depot/perl/perl.c#633 (text) ====

@@ -507,6 +507,11 @@
     /* We must account for everything.  */
 
     /* Destroy the main CV and syntax tree */
+    /* Do this now, because destroying ops can cause new SVs to be generated
+       in Perl_pad_swipe, and when running with -DDEBUG_LEAKING_SCALARS they
+       PL_curcop to point to a valid op from which the filename structure
+       member is copied.  */
+    PL_curcop = &PL_compiling;
     if (PL_main_root) {
        /* ensure comppad/curpad to refer to main's pad */
        if (CvPADLIST(PL_main_cv)) {
@@ -515,7 +520,6 @@
        op_free(PL_main_root);
        PL_main_root = Nullop;
     }
-    PL_curcop = &PL_compiling;
     PL_main_start = Nullop;
     SvREFCNT_dec(PL_main_cv);
     PL_main_cv = Nullcv;

Reply via email to