Closed p5pRT closed 21 years ago
Hi\,
This happened on Perl 5.8.0\, RedHat 8.0. Here is a code fragment that produces the error listed below it:
use IO::File (); local $/;
foreach (sort keys %altnames) { my $fh = IO::File->new; my ($hr_title) = m/(.*)\.txt/; print("\
I have found that I get the error even for one loop. I inserted "last;" just after the close to test.
If I comment the print($_) statement\, I still get the error.
If I comment the "while (\<$fh>)" loop entirely\, the errors go away!!
Here is the error log:
Unbalanced string table refcount: (1) for "Oracle.txt" during global destruction.
I was able to correct the error by using a lexical variable in the outer loop\, thus avoiding the $_ variable at 2 levels.
my $fh = IO::File->new;
foreach* my $file* (sort keys %altnames) { # insert each file into an IMG tag my ($hr_title) = ( $file =~ m/(.*)\.txt/ ); print "\
Paul Dyer (via RT) wrote:
This happened on Perl 5.8.0\, RedHat 8.0. Here is a code fragment that produces the error listed below it:
I can't reproduce this. Is your code fragment sufficient ? I don't see a definition of %altnames.
There have been reports of problems due to UTF8 locales\, notably under RedHat 8.0. What's your locale ? Does the problem run away when you run your script under the C locale ?
Rafael Garcia-Suarez (via RT) wrote:
Paul Dyer (via RT) wrote:
This happened on Perl 5.8.0\, RedHat 8.0. Here is a code fragment that produces the error listed below it:
I can't reproduce this. Is your code fragment sufficient ? I don't see a definition of %altnames.
There have been reports of problems due to UTF8 locales\, notably under RedHat 8.0. What's your locale ? Does the problem run away when you run your script under the C locale ?
Hi\,
I'm attaching the whole script. I am running under Apache\, ModPerl.
I used the Apache::File and IO::File modules and got the errors on both.
I am using RedHat 8.0 and 7.3 with the same results. I don't know what the character set is.
Paul
package MyApache::BookPicture; # ~www/lib/perl/MyApache/BookPicture.pm
use strict; use warnings; use Apache::Constants qw(:common); use DirHandle (); use Apache::File ();
sub handler { my $r = shift;
my $dir_uri = $r->dir_config('PictureDir'); unless ($dir_uri) { $r->log_reason("No PictureDir configured"); return SERVER_ERROR; } $dir_uri .= "/" unless $dir_uri =~ m:/$:;
my $subr = $r->lookup_uri($dir_uri); my $dir = $subr->filename; # Get list of images in the directory. my $dh = DirHandle->new($dir); unless ($dh) { $r->log_error("Can't read directory $dir: $!"); return SERVER_ERROR; }
my @files; my %altnames; for my $entry ($dh->read) { # get the file's MIME type my $rr = $subr->lookup_uri($entry); my $type = $rr->content_type; next unless $type and $type =~ m:^text/:; push @files\, $rr->uri; $altnames{$entry} = $rr->uri; } $dh->close; unless (@files) { $r->log_error("No image files in directory"); return SERVER_ERROR; }
$r->content_type('text/html'); $r->send_http_header; return OK if $r->header_only;
print(\<\<END); \ \
\my $fh; foreach (sort keys %altnames) { # insert each file into an IMG tag my ($hr_title) = m/(.*)\.txt/; print("\
return OK; }
1; __END__
Paul Dyer wrote:
I'm attaching the whole script. I am running under Apache\, ModPerl.
It's possible that it's a mod_perl problem. The startup/shutdown process of mod_perl is more complicated than for a standalone perl interpreter.
It's possible also that the problem is not related at all to mod_perl\, but in this case\, to fix it\, it would be handy to be able to replicate it without mod_perl.
Anyway\, the error you're getting is an (undocumented) internal warning that occurs on destruction of a perl interpreter. It's probably harmless.
I used the Apache::File and IO::File modules and got the errors on both.
I am using RedHat 8.0 and 7.3 with the same results. I don't know what the character set is.
The output of the locale command is usually sufficient.
On Wed\, Mar 19\, 2003 at 03:57:21AM -0000\, Paul Dyer wrote:
Here is the error log:
Unbalanced string table refcount: (1) for "Oracle.txt" during global destruction.
On Fri\, Mar 21\, 2003 at 05:52:49PM +0100\, Rafael Garcia-Suarez wrote:
Paul Dyer wrote:
I'm attaching the whole script. I am running under Apache\, ModPerl.
It's possible that it's a mod_perl problem. The startup/shutdown process of mod_perl is more complicated than for a standalone perl interpreter.
It's possible also that the problem is not related at all to mod_perl\, but in this case\, to fix it\, it would be handy to be able to replicate it without mod_perl.
I'll second that. I can't replicate it here with pure perl - I don't have modperl or a UTF8 locale.
Anyway\, the error you're getting is an (undocumented) internal warning that occurs on destruction of a perl interpreter. It's probably harmless.
I'm surprised that there is only 1 error line. I thought that unbalanced string table refcounts usually came in pairs - one was too high\, and another was too low. (effectively a matched set). I wonder if something in the internals is clearing all the flags in $_ at some point\, rather than correctly undef()ing it. In 5.8 keys will generate a list of scalars which point directly to the string table used for hash keys (this is the table that the error message refers to) In turn\, foreach aliases $_ to the items in the list\, so $_ is pointing into the string table. If the internals clear $_ properly\, then the string table reference is tidied up\, and everything balances. But if something (I'm suspicious of the inner foreach) just blasts $_ instead\, then the reference is lost.
I used the Apache::File and IO::File modules and got the errors on both.
I am using RedHat 8.0 and 7.3 with the same results. I don't know what the character set is.
The output of the locale command is usually sufficient.
the output from perl -V would contain it. (plus a lot of other information)
If you're able to make a test case that doesn't need mod_perl that would be really useful. I think that the string table reference counts are only checked on perl compiled with -DDEBUGGING. I presume that the perl you have is\, given that mod_perl is warning. You can check - this perl is suitable:
$ perl5.8.0-32-g -D -e0
EXECUTING...
This perl is not:
$ perl5.8.0 -D -e0 Recompile perl with -DDEBUGGING to use -D switch
Nicholas Clark
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) \
\
Migrated from rt.perl.org#21614 (status was 'resolved')
Searchable as RT21614$