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

Re: [perl #21614] 5.8.0 Unbalanced string table refcount

Thread Next
From:
Nicholas Clark
Date:
March 23, 2003 10:04
Subject:
Re: [perl #21614] 5.8.0 Unbalanced string table refcount
Message ID:
20030323175958.GH281@Bagpuss.unfortu.net
OK. My suspicions were wrong, in that it's not a UTF8 local issue.
Also I was wrong in my understanding of the string table - the string table
warning occurs independent of -DDEBUGGING

On Sat, Mar 22, 2003 at 10:16:17PM -0600, Paul Dyer wrote:

> Here is some feedback, but not yet a test case w/o modperl:
> 
> >>locale
> LANG=en_US
> LC_CTYPE="en_US"
> LC_NUMERIC="en_US"
> LC_TIME="en_US"
> LC_COLLATE="en_US"
> LC_MONETARY="en_US"
> LC_MESSAGES="en_US"
> LC_PAPER="en_US"
> LC_NAME="en_US"
> LC_ADDRESS="en_US"
> LC_TELEPHONE="en_US"
> LC_MEASUREMENT="en_US"
> LC_IDENTIFICATION="en_US"
> LC_ALL=

> >>perl -D -e0
> Recompile perl with -DDEBUGGING to use -D switch

On Sat, Mar 22, 2003 at 10:45:01PM -0600, Paul Dyer wrote:

> I am attaching an attempt to reproduce the error w/o modperl. I used 
> almost the same code, removing all the apache stuff. Sorry, but I don't 
> get the error. I checked my httpd compile. On this machine, RedHat 8.0, 
> mod_perl.c is static. On the other RedHat machine, mod_perl.c is a dso 
> and the character set is en_US.iso885915.
> Paul
> 

> #!/usr/local/bin/perl -w
> # ~www/lib/perl/MyApache/BookPicture.pm
> 
> use strict;
> use warnings;
> use DirHandle ();
> use IO::File ();
> 
>     my $r = shift;
> 
>     my $dir = "/usr/local/apache/htdocs/mercury/pictures/Books";
> 
>     # Get list of images in the directory.
>     my $dh = DirHandle->new($dir);
>     unless ($dh) {
> 	print("Can't read directory $dir: $!");
> 	exit 0;
>     }
> 
>     my @files;
>     my %altnames;
>     for my $entry ($dh->read) {
>         next unless ( $entry =~ m/(.*)\.txt/ );
> 	push @files, $entry;
> 	$altnames{$entry} = $entry;
>     }
>     $dh->close;
>     unless (@files) {
> 	print("No image files in directory");
> 	exit 0;
>     }
> 
>     my $fh;
>     foreach (sort keys %altnames) { # insert each file into an IMG tag
>       my ($hr_title) = m/(.*)\.txt/;
>       print("<hr><h1 align=center> $hr_title </h1>\n");
>       my $source = join '/', $dir, $_;
>       unless ($fh = IO::File->new($source)) {
>          print("Couldn't open $source for reading: $!");
>          exit 0;
>          }
>       while (<$fh>) { # read the text files with IMG tags.
>           print ;
>           }
>       close $fh;
>       }
>     print("<!--#FOOTER -->");
>     print('</BODY></HTML>');
> 
>   exit 1;

When I run that test code under valgrind (on x86 Debian), with $dir changed
to a directory containing 1 file, Oracle.txt, with 1 line "Hello World" I
see memory access errors:

$ valgrind ./perl -I lib BookPicture.pl
==22221== valgrind-1.0.4, a memory error detector for x86 GNU/Linux.
==22221== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
==22221== Estimated CPU clock rate is 262 MHz
==22221== For more details, rerun with: -v
==22221==
==22221== Invalid read of size 4
==22221==    at 0x808CE25: Perl_pad_allocmy (/home/nick/5.8.0-i-g/op.c:217)
==22221==    by 0x807FF08: S_pending_ident (/home/nick/5.8.0-i-g/toke.c:5224)
==22221==    by 0x80716CB: Perl_yylex (/home/nick/5.8.0-i-g/toke.c:2201)
==22221==    by 0x80894E9: Perl_yyparse (/home/nick/5.8.0-i-g/perly.c:1470)
==22221==    Address 0x40BFC510 is 0 bytes after a block of size 1008 alloc'd
==22221==    at 0x4003D78E: malloc (vg_clientfuncs.c:100)
==22221==    by 0x80B80C8: Perl_safesysmalloc (/home/nick/5.8.0-i-g/util.c:78)
==22221==    by 0x80DD3F7: S_more_xpv (/home/nick/5.8.0-i-g/sv.c:740)
==22221==    by 0x80DD32D: S_new_xpv (/home/nick/5.8.0-i-g/sv.c:715)
==22221==
==22221== Invalid read of size 4
==22221==    at 0x808CE33: Perl_pad_allocmy (/home/nick/5.8.0-i-g/op.c:217)
==22221==    by 0x807FF08: S_pending_ident (/home/nick/5.8.0-i-g/toke.c:5224)
==22221==    by 0x80716CB: Perl_yylex (/home/nick/5.8.0-i-g/toke.c:2201)
==22221==    by 0x80894E9: Perl_yyparse (/home/nick/5.8.0-i-g/perly.c:1470)
==22221==    Address 0x40BFC510 is 0 bytes after a block of size 1008 alloc'd
==22221==    at 0x4003D78E: malloc (vg_clientfuncs.c:100)
==22221==    by 0x80B80C8: Perl_safesysmalloc (/home/nick/5.8.0-i-g/util.c:78)
==22221==    by 0x80DD3F7: S_more_xpv (/home/nick/5.8.0-i-g/sv.c:740)
==22221==    by 0x80DD32D: S_new_xpv (/home/nick/5.8.0-i-g/sv.c:715)
==22221==
==22221== pthread_mutex_destroy: mutex is still in use
==22221==    at 0x40273C90: pthread_error (vg_libpthread.c:275)
==22221==    by 0x40274BB4: __pthread_mutex_destroy (vg_libpthread.c:952)
==22221==    by 0x403202E9: (within /lib/libc-2.3.1.so)
==22221==    by 0x81266C6: Perl_pp_closedir (/home/nick/5.8.0-i-g/pp_sys.c:3925)
<hr><h1 align=center> Oracle </h1>
Hello World
valgrind's libpthread.so: KLUDGED call to: siglongjmp (cleanup handlers are ignored)
valgrind's libpthread.so: KLUDGED call to: pthread_cond_destroy
<!--#FOOTER --></BODY></HTML>==22221==
==22221== ERROR SUMMARY: 9 errors from 3 contexts (suppressed: 0 from 0)
==22221== malloc/free: in use at exit: 582286 bytes in 12712 blocks.
==22221== malloc/free: 23363 allocs, 10651 frees, 1128739 bytes allocated.
==22221== For a detailed leak analysis,  rerun with: --leak-check=yes
==22221== For counts of detected errors, rerun with: -v


Running with maintperl (5.8.1 to be) or bleadperl (the current development
snapshot) valgrind reports no memory errors. So there does seem to be a bug
in 5.8.0, and it seems to have been fixed for 5.8.1
However, I can't be sure if this illegal memory access is actually the
same bug as you're seeing. I'm a bit confused by all this, because valgrind
seems to be reporting errors in the pad code, and pads have been substantially
reworked for bleadperl, but not maintperl. Hence I'm surprised that the bug
seems to be fixed in both branches, given that the implementation differs.

I don't know if it's possible to run mod_perl under valgrind, to see if these
memory errors correlate with what you see there.

Nicholas Clark

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