Closed p5pRT closed 17 years ago
When using both threads and the Bencode module\, Perl will crash on termination of a thread that has been detached or should be joined now. I could reproduce the crash with the following test script on i386\, x86_64 and ppc32 (so the problem seems to be architecture independent):
#!/usr/bin/perl -w
use strict; use warnings;
use threads; use Bencode;
sub active_mcast_threads_each() {}
my $thread = threads->new(\&active_mcast_threads_each); $thread->join();
The Bencode module (from CPAN) does not include external libraries\, it consists of plain Perl code. I tried to track the problem down and found that it occurs only when a regular expression in Bencode's _bdecode_chuck sub has been evaluated (this is done on initialization of the module\, with $_ = 'i1e'). The corrensponding code from Bencode is:
my $str_rx = qr/ \G ( 0 | [1-9] \d* ) : ( (??{ # workaround: can't use quantifies > 32766 in patterns\, # so for eg. 65536 chars produce something like '(?s).{32766}.{32766}.{4}' $q = int( $^N \/ 32766 ); $r = $^N % 32766; $q--\, $r += 32766 if $q and not $r; "(?s)" . ( ".{32766}" x $q ) . ".{$r}" }) ) /x;
m/$str_rx/xgc;
When executing the script using Bencode and $thread->join (or $thread->detach followed by sleep 1 to make sure the thread has enough time to return)\, the following error message is printed:
*** glibc detected *** /usr/bin/perl: double free or corruption (!prev): 0x00000000007998e0 *** ======= Backtrace: ========= /lib64/libc.so.6[0x2b039f7f637e] /lib64/libc.so.6(__libc_free+0x6c)[0x2b039f7f799c] /usr/bin/perl(Perl_pregfree+0x159)[0x462b89] /usr/bin/perl(perl_destruct+0xe34)[0x426094] /usr/lib/perl5/5.8.8/x86_64-linux-thread-multi/auto/threads/threads.so[0x2b039fa1deea] /usr/lib/perl5/5.8.8/x86_64-linux-thread-multi/auto/threads/threads.so(XS_threads_join+0x25b)[0x2b039fa1e6db] /usr/bin/perl(Perl_pp_entersub+0x402)[0x482cf2] /usr/bin/perl(Perl_runops_debug+0x11e)[0x46515e] /usr/bin/perl(perl_run+0x3fc)[0x424c1c] /usr/bin/perl(main+0xe4)[0x41d6c4] /lib64/libc.so.6(__libc_start_main+0xf4)[0x2b039f7a8154] /usr/bin/perl[0x41d549] ======= Memory map: ======== 00400000-00533000 r-xp 00000000 08:02 37752 /usr/bin/perl 00632000-00639000 rw-p 00132000 08:02 37752 /usr/bin/perl 00639000-007a7000 rw-p 00639000 00:00 0 [heap] 40000000-40001000 ---p 40000000 00:00 0 40001000-40801000 rw-p 40001000 00:00 0 2aaaaab00000-2aaaaab21000 rw-p 2aaaaab00000 00:00 0 2aaaaab21000-2aaaaac00000 ---p 2aaaaab21000 00:00 0 2aaaaac00000-2aaaaac0d000 r-xp 00000000 08:02 22761 /lib64/libgcc_s.so.1 2aaaaac0d000-2aaaaad0c000 ---p 0000d000 08:02 22761 /lib64/libgcc_s.so.1 2aaaaad0c000-2aaaaad0d000 rw-p 0000c000 08:02 22761 /lib64/libgcc_s.so.1 2b039f1c5000-2b039f1e0000 r-xp 00000000 08:02 17809 /lib64/ld-2.4.so 2b039f1e0000-2b039f1e1000 rw-p 2b039f1e0000 00:00 0 2b039f1e1000-2b039f1e2000 r--p 00000000 08:02 18644 /usr/lib/locale/de_DE.utf8/LC_IDENTIFICATION 2b039f1e2000-2b039f1e9000 r--s 00000000 08:02 20831 /usr/lib64/gconv/gconv-modules.cache 2b039f1e9000-2b039f1ea000 r--p 00000000 08:02 21296 /usr/lib/locale/de_DE.utf8/LC_MEASUREMENT 2b039f1ea000-2b039f1eb000 r--p 00000000 08:02 21128 /usr/lib/locale/de_DE.utf8/LC_TELEPHONE 2b039f1eb000-2b039f1ec000 r--p 00000000 08:02 18643 /usr/lib/locale/de_DE.utf8/LC_ADDRESS 2b039f1ec000-2b039f1ed000 r--p 00000000 08:02 18646 /usr/lib/locale/de_DE.utf8/LC_NAME 2b039f1ed000-2b039f1ee000 r--p 00000000 08:02 21292 /usr/lib/locale/de_DE.utf8/LC_PAPER 2b039f1ee000-2b039f1ef000 r--p 00000000 08:02 21153 /usr/lib/locale/de_DE.utf8/LC_MESSAGES/SYS_LC_MESSAGES 2b039f1ef000-2b039f1f0000 r--p 00000000 08:02 21129 /usr/lib/locale/de_DE.utf8/LC_MONETARY 2b039f201000-2b039f202000 rw-p 2b039f201000 00:00 0 2b039f202000-2b039f2d9000 r--p 00000000 08:02 21298 /usr/lib/locale/de_DE.utf8/LC_COLLATE 2b039f2d9000-2b039f2da000 r--p 00000000 08:02 18647 /usr/lib/locale/de_DE.utf8/LC_TIME 2b039f2da000-2b039f2db000 r--p 00000000 08:02 21221 /usr/lib/locale/de_DE.utf8/LC_NUMERIC 2b039f2e0000-2b039f2e2000 rw-p 0001b000 08:02 17809 /lib64/ld-2.4.so 2b039f2e2000-2b039f336000 r-xp 00000000 08:02 17824 /lib64/libm-2.4.so 2b039f336000-2b039f435000 ---p 00054000 08:02 17824 /lib64/libm-2.4.so 2b039f435000-2b039f437000 rw-p 00053000 08:02 17824 /lib64/libm-2.4.so 2b039f437000-2b039f439000 r-xp 00000000 08:02 17822 /lib64/libdl-2.4.so 2b039f439000-2b039f539000 ---p 00002000 08:02 17822 /lib64/libdl-2.4.so 2b039f539000-2b039f53b000 rw-p 00002000 08:02 17822 /lib64/libdl-2.4.so 2b039f53b000-2b039f544000 r-xp 00000000 08:02 17820 /lib64/libcrypt-2.4.so 2b039f544000-2b039f643000 ---p 00009000 08:02 17820 /lib64/libcrypt-2.4.so 2b039f643000-2b039f646000 rw-p 00008000 08:02 17820 /lib64/libcrypt-2.4.so 2b039f646000-2b039f675000 rw-p 2b039f646000 00:00 0 2b039f675000-2b039f686000 r-xp 00000000 08:02 17842 /lib64/libpthread-2.4.so 2b039f686000-2b039f785000 ---p 00011000 08:02 17842 /lib64/libpthread-2.4.so 2b039f785000-2b039f787000 rw-p 00010000 08:02 17842 /lib64/libpthread-2.4.so 2b039f787000-2b039f78b000 rw-p 2b039f787000 00:00 0 2b039f78b000-2b039f8b1000 r-xp 00000000 08:02 17816 /lib64/libc-2.4.so 2b039f8b1000-2b039f9b1000 ---p 00126000 08:02 17816 /lib64/libc-2.4.so 2b039f9b1000-2b039f9b4000 r--p 00126000 08:02 17816 /lib64/libc-2.4.so 2b039f9b4000-2b039f9b6000 rw-p 00129000 08:02 17816 Abgebrochen
On Mon\, Jan 15\, 2007 at 04:45:16AM -0800\, Kevin Wolf wrote:
When using both threads and the Bencode module\, Perl will crash on termination of a thread that has been detached or should be joined now.
Thanks for the report. I can reduce the problem to
use threads ();
"i" =~ /\GX(?{})/;
sub foo() {} threads->create(\&foo)->join;
and is now fixed in bleedperl with the change below
Dave
-- print+qq&$}$"$/$s$\,$*${d}$g$s$@$.$q$\,$:$.$q$^$\,$@$*$~$;$.$q$m&if+map{m\,^\d{0\\,}\,\,${$::{$'}}=chr($"+=$&||1)}q&10m22\,42}6:17*2~2.3@3;^2dg3q/s"&=~m*\d\*.*g
Change 29837 by davem@davem-pigeon on 2007/01/15 18:19:20
when cloning PL_regex_pad\, copy SVf_BREAK flag too
Affected files ...
... //depot/perl/sv.c#1351 edit
Differences ...
==== //depot/perl/sv.c#1351 (text) ====
@@ -11025\,6 +11025\,8 @@ newSViv(PTR2IV(CALLREGDUPE( INT2PTR(REGEXP *\, SvIVX(regex))\, param)))) ; + if (SvFLAGS(regex) & SVf_BREAK) + SvFLAGS(sv) |= SVf_BREAK; /* unrefcnted PL_curpm */ av_push(PL_regex_padav\, sv); } }
The RT System itself - Status changed from 'new' to 'open'
@iabyn - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#41273 (status was 'resolved')
Searchable as RT41273$