develooper Front page | perl.perl5.porters | Postings from September 2003

[PATCH?] Re: [perl #23576] valgrind errors for /(?{})/ in t/op/pat.t

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
September 13, 2003 16:10
Subject:
[PATCH?] Re: [perl #23576] valgrind errors for /(?{})/ in t/op/pat.t
Message ID:
20030913231023.GD19465@fdgroup.com
On Mon, Aug 25, 2003 at 07:12:42PM -0000, Nicholas Clark wrote:
> The first 2 valgrind errors on t/op/pat.t boil down to this.
> They're from the two (? constructions starting at column 8.
> 
> #!./perl
> 
> @a = 1 .. 2;
> 
> m/
> 	(?{ 0 })
> 	(?(?{ 0 })
> 	 )	
>    /x;
> 
> # bug is during compile time
> BEGIN {exit;}
> __END__
> 
> ==27761== Invalid read of size 2
> ==27761==    at 0x80FFC29: Perl_sv_compile_2op (pp_ctl.c:2666)
> ==27761==    by 0x80A24B2: S_reg (regcomp.c:2239)
> ==27761==    by 0x80A467E: S_regatom (regcomp.c:2845)
> ==27761==    by 0x80A3AAA: S_regpiece (regcomp.c:2622)
> ==27761==    Address 0x413A2CE8 is 16 bytes inside a block of size 32 free'd
> ==27761==    at 0x40026C15: free (vg_replace_malloc.c:220)
> ==27761==    by 0x80B0628: Perl_safesysfree (util.c:143)
> ==27761==    by 0x8089B9A: Perl_op_free (op.c:334)
> ==27761==    by 0x8089B31: Perl_op_free (op.c:321)

The following patch makes the valgrind errors go away, but I'm not
sure whether I'm just masking the problem.

After op_free(), PL_op may be left pointing at the just-freed op.
Later, Perl_sv_compile_2op () tries to use PL_op, which is no longer
valid. The patch makes op_free() set PL_op to null if it equals the op
being freed. However, I don't know whether instead

* the caller of op_free() should be sorting out PL_op, or
* that op_free(0 shopuldn'y be getting called on PL_op, or
* that Perl_sv_compile_2op() shouldn't be relying on PL_op to be valid.

-- 
The perl5 internals are a complete mess. It's like Jenga - to get the
perl5 tower taller and do something new you select a block somewhere in
the middle, with trepidation pull it out slowly, and then carefully
balance it somewhere new, hoping the whole edifice won't collapse as a
result.
		- Nicholas Clark.

--- op.c-	Sat Sep 13 23:59:29 2003
+++ op.c	Sun Sep 14 00:01:24 2003
@@ -256,6 +256,8 @@ Perl_op_free(pTHX_ OP *o)
 
     op_clear(o);
     FreeOp(o);
+    if (PL_op == o)
+	PL_op = Nullop;
 }
 
 void

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About