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

Empty subroutine as object method segfaults in 5.8.2 (sometimes)

Thread Next
From:
Elizabeth Mattijsen
Date:
November 9, 2003 05:03
Subject:
Empty subroutine as object method segfaults in 5.8.2 (sometimes)
Message ID:
p05111b09bbd3deb12c8d@[192.168.56.3]
I'm afraid I haven't been paying enough attention to p5p lately.  I 
too was surprised by the arrival of 5.8.2, so I haven't tested my 
Thread::xxx modules with 5.8.2-RCx.  I guess I have to get used to 
the increased frequency of releases as well.  Which is a good thing!

Anyway, one of my Thread modules, Thread::Conveyor, segfaults during 
a make test in 5.8.2.  This affects Thread::Pool, which is more used.

The core dump is not giving any usable information, even with a debug 
enabled Perl (could this have to do that the segfault occurs inside a 
dynamically loaded piece of code?)

When checking where the error occurred, I found that it happened when 
calling an object method.  That object method (for that particular 
blessed object) consisted of:

   sub shutdown {}

i.e. nothing.  Since this method isn't supposed to return anything 
(but couldn't be inherited), I chose to do it this way.

The funny thing is that when I replace the subroutine with:

   sub shutdown { undef }

the problem (and the segfault) goes away.

I've been trying to reduce the problem to a simple case:

   package Foo;
   sub new { bless {},shift }
   sub empty {}

   package main;
   use threads;
   my $object = Foo->new;
   $object->empty;

but this just runs without any problems, even under valgrind, so it 
must be something trickier that I'm doing.

I'll be issuing new versions of my Thread::xxx modules to prevent 
failures in 5.8.2, but thought I'd report this to p5p nonetheless

Liz


The valgrind output for the Thread::Conveyor test-suite:

$ valgrind perl5.8.2-threaded-debug -Ilib t/Conveyor.t
==21280== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==21280== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
==21280== Using valgrind-20030725, a program supervision framework 
for x86-linux.
==21280== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
==21280== Estimated CPU clock rate is 2825 MHz
==21280== For more details, rerun with: -v
==21280==
==21280== valgrind's libpthread.so: KLUDGED call to: pthread_cond_destroy
==21280== valgrind's libpthread.so: KLUDGED call to: pthread_cond_destroy
1..105
==21280== valgrind's libpthread.so: KLUDGED call to: siglongjmp 
(cleanup handlers are ignored)
==21280== valgrind's libpthread.so: KLUDGED call to: siglongjmp 
(cleanup handlers are ignored)
ok 1 - use Thread::Conveyor;
# test belt optimized for cpu
ok 2 - check object type isa Thread::Conveyor
ok 3 - Thread::Conveyor::Throttled->can(...)
ok 4 - check number boxes on belt
==21280== valgrind's libpthread.so: KLUDGED call to: pthread_cond_destroy
ok 5 - check \# elements simple list
ok 6 - check simple list
ok 7 - check \# elements list ref
ok 8 - check type of list ref
ok 9 - check list ref
ok 10 - check \# elements hash ref, \#1
ok 11 - check type of hash ref, \#1
ok 12 - check \# elements hash ref, \#2
ok 13 - check type of hash ref, \#2
ok 14 - check \# elements hash ref, \#3
ok 15 - check type of hash ref, \#3
ok 16 - check hash ref
ok 17 - check \# elements dontwait
==21280== Invalid read of size 4
==21280==    at 0x80BB5DA: Perl_runops_debug (dump.c:1438)
==21280==    by 0x8065068: S_run_body (perl.c:1860)
==21280==    by 0x8064AD2: perl_run (perl.c:1779)
==21280==    by 0x805FC82: main (perlmain.c:86)
==21280==    Address 0x41D4A1EC is 8 bytes inside a block of size 24 free'd
==21280==    at 0x400296BF: free (vg_replace_malloc.c:220)
==21280==    by 0x80BC048: Perl_safesysfree (util.c:143)
==21280==    by 0x80922BA: Perl_op_free (op.c:325)
==21280==    by 0x80A2B8C: Perl_peep (op.c:6378)
==21280==
==21280== Invalid read of size 1
==21280==    at 0x80FAAC0: Perl_pp_stub (pp.c:36)
==21280==    by 0x80BB5DE: Perl_runops_debug (dump.c:1438)
==21280==    by 0x8065068: S_run_body (perl.c:1860)
==21280==    by 0x8064AD2: perl_run (perl.c:1779)
==21280==    Address 0x41D4A1F8 is 20 bytes inside a block of size 24 free'd
==21280==    at 0x400296BF: free (vg_replace_malloc.c:220)
==21280==    by 0x80BC048: Perl_safesysfree (util.c:143)
==21280==    by 0x80922BA: Perl_op_free (op.c:325)
==21280==    by 0x80A2B8C: Perl_peep (op.c:6378)
==21280==
==21280== Invalid read of size 1
==21280==    at 0x80FAAD0: Perl_pp_stub (pp.c:36)
==21280==    by 0x80BB5DE: Perl_runops_debug (dump.c:1438)
==21280==    by 0x8065068: S_run_body (perl.c:1860)
==21280==    by 0x8064AD2: perl_run (perl.c:1779)
==21280==    Address 0x41D4A1F8 is 20 bytes inside a block of size 24 free'd
==21280==    at 0x400296BF: free (vg_replace_malloc.c:220)
==21280==    by 0x80BC048: Perl_safesysfree (util.c:143)
==21280==    by 0x80922BA: Perl_op_free (op.c:325)
==21280==    by 0x80A2B8C: Perl_peep (op.c:6378)
==21280==
==21280== Invalid read of size 1
==21280==    at 0x80FAAE0: Perl_pp_stub (pp.c:36)
==21280==    by 0x80BB5DE: Perl_runops_debug (dump.c:1438)
==21280==    by 0x8065068: S_run_body (perl.c:1860)
==21280==    by 0x8064AD2: perl_run (perl.c:1779)
==21280==    Address 0x41D4A1F8 is 20 bytes inside a block of size 24 free'd
==21280==    at 0x400296BF: free (vg_replace_malloc.c:220)
==21280==    by 0x80BC048: Perl_safesysfree (util.c:143)
==21280==    by 0x80922BA: Perl_op_free (op.c:325)
==21280==    by 0x80A2B8C: Perl_peep (op.c:6378)
==21280==
==21280== Invalid read of size 4
==21280==    at 0x80FAB45: Perl_pp_stub (pp.c:38)
==21280==    by 0x80BB5DE: Perl_runops_debug (dump.c:1438)
==21280==    by 0x8065068: S_run_body (perl.c:1860)
==21280==    by 0x8064AD2: perl_run (perl.c:1779)
==21280==    Address 0x41D4A1E4 is 0 bytes inside a block of size 24 free'd
==21280==    at 0x400296BF: free (vg_replace_malloc.c:220)
==21280==    by 0x80BC048: Perl_safesysfree (util.c:143)
==21280==    by 0x80922BA: Perl_op_free (op.c:325)
==21280==    by 0x80A2B8C: Perl_peep (op.c:6378)
==21280== valgrind's libpthread.so: KLUDGED call to: siglongjmp 
(cleanup handlers are ignored)
Scalars leaked: 1
# Looks like you planned 105 tests but only ran 17.
==21280==
==21280== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 9 from 2)
==21280== malloc/free: in use at exit: 221053 bytes in 125 blocks.
==21280== malloc/free: 75824 allocs, 75699 frees, 17086815 bytes allocated.

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