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

Simple @INC hook core dump

Thread Next
From:
Gisle Aas
Date:
October 7, 2003 12:23
Subject:
Simple @INC hook core dump
Message ID:
lrpth8kg38.fsf@caliper.activestate.com
The following simple program core dumps with perl-5.8.1:

---------------------------------------------------->%-----------
#!perl

BEGIN {
    unshift @INC, sub {
        my $content = qq("abc";\n);
        return (sub {
            return 0 unless length $content;
            $_ = $content;
            $content = "";
            return 1;
        });
    }
}

$var ||= do 'var.pl';
print "not " unless $var eq "abc";
print "ok 1\n";
---------------------------------------------------->%-----------

I would be grateful if somebody can tell me why.  If I change the $var
assignment to be a plain '=' then everything looks fine.

gdb says:

(gdb) bt
#0  chunk_free (ar_ptr=0x401c9c80, p=0x8119478) at malloc.c:3180
#1  0x40117fc0 in __libc_free (mem=0x8119480) at malloc.c:3154
#2  0x080b0444 in Perl_sv_setsv_flags ()
#3  0x080a5452 in Perl_pp_sassign ()
#4  0x080a5122 in Perl_runops_standard ()
#5  0x08060f98 in S_run_body ()
#6  0x08060cea in perl_run ()
#7  0x0805e52b in main ()
#8  0x400b7336 in __libc_start_main (main=0x805e4a0 <main>, argc=2, ubp_av=0xbffff9c4,
    init=0x805d624 <_init>, fini=0x80fb8a0 <_fini>, rtld_fini=0x4000d2fc <_dl_fini>,
    stack_end=0xbffff9bc) at ../sysdeps/generic/libc-start.c:129

valgrind says:

==32219== valgrind-1.0.1, a memory error detector for x86 GNU/Linux.
==32219== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
==32219== Estimated CPU clock rate is 350 MHz
==32219== For more details, rerun with: -v
==32219==
==32219== Invalid free() / delete / delete[]
==32219==    at 0x40045CD9: free (vg_clientfuncs.c:180)
==32219==    by 0x80B0444: Perl_sv_setsv_flags (in /local/perl/5.8.1/bin/perl)
==32219==    by 0x80A5452: Perl_pp_sassign (in /local/perl/5.8.1/bin/perl)
==32219==    by 0x80A5122: Perl_runops_standard (in /local/perl/5.8.1/bin/perl)
==32219==    Address 0x40E6E2E0 is 648 bytes inside a block of size 1008 alloc'd
==32219==    at 0x40045A04: malloc (vg_clientfuncs.c:100)
==32219==    by 0x809796C: Perl_safesysmalloc (in /local/perl/5.8.1/bin/perl)
==32219==    by 0x80ABED9: S_more_sv (in /local/perl/5.8.1/bin/perl)
==32219==    by 0x80B1179: Perl_newSV (in /local/perl/5.8.1/bin/perl)

Regards,
Gisle

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