develooper Front page | perl.perl5.porters | Postings from July 2013

[perl #117823] <glob*> under 'use threads;' segfaults

Thread Next
From:
Father Chrysostomos via RT
Date:
July 7, 2013 00:53
Subject:
[perl #117823] <glob*> under 'use threads;' segfaults
Message ID:
rt-3.6.HEAD-2552-1373158410-1381.117823-15-0@perl.org
On Wed May 01 04:55:31 2013, trast@inf.ethz.ch wrote:
> It seems <glob*> contains a race when used in parallel in threads.
>    This
> test case reliably spews a few errors, and then segfaults, when I run
>    it
> on perl v5.16.2 (stock opensuse 12.3):
> 
> ----- 8< -----
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> use threads;
> use threads::shared;
> 
> my $nthread = 20;
> 
> sub work {
>     foreach (1..10000) {
> 	my @files = <*.supp>;
>     }
> }
> 
> my @threads;
> foreach my $i (1..$nthread) {
>     push @threads, threads->create(\&work);
> }
> 
> foreach my $t (@threads) {
>     $t->join();
> }
> ----- >8 -----
> 
> There are two kinds of errors shown:
> 
> a) Attempt to free unreferenced scalar: SV 0xd1e738, Perl interpreter:
>    0xdf8900 at /home/thomas/tmp/perl-thread-glob-test.pl line 13.
> 
> b) Thread 1 terminated abnormally: sv_upgrade from type 255 down to
>    type 11 at perl-thread-glob-test.pl line 13.
> 
> Followed by a segmentation fault or (rarely) a bus error.

I can produce this bug on Mac OS X as well.

I also see ‘Attempt to free nonexistent shared string’, ‘Assertion
failed’, ‘panic: free from wrong pool’.  The errors I get are different
in each run.

I have tried to diagnose this, but I am stumped.

It has nothing to do with readdir.  I get the same thing with <{a}>, but
<{a,b}{a,b}> triggers it more reliably.

The bug can’t be in glob_expand.  I changed glob_expand to return early,
and the memory corruption persists.

But I can’t see anything wrong with the code.  Nothing uses globals.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=117823

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