Front page | perl.perl5.porters |
Postings from November 2008
[perl #60680] Perl 5.10 memory leak: 'use Scalar::Util qw(weaken); weaken({}) while 1'
Thread Next
From:
Petr Pajas
Date:
November 20, 2008 06:13
Subject:
[perl #60680] Perl 5.10 memory leak: 'use Scalar::Util qw(weaken); weaken({}) while 1'
Message ID:
rt-3.6.HEAD-10965-1227124927-306.60680-75-0@perl.org
# New Ticket Created by Petr Pajas
# Please include the string: [perl #60680]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=60680 >
This is a bug report for perl from pajas@ufal.mff.cuni.cz,
generated with the help of perlbug 1.36 running under perl 5.10.0.
-----------------------------------------------------------------
[Please enter your report here]
Hi,
the following one-liner leaks as hell with Perl 5.10, but runs fine with Perl
5.8.8:
perl -MScalar::Util -e 'Scalar::Util::weaken({}) while 1'
Similar code with arrays does *not* leak with Perl 5.10:
perl -MScalar::Util -e 'Scalar::Util::weaken([]) while 1'
A more complex example is given below. The leak can be avoided by
blessing the hashref and emptying the hash with %$self=() in the
destructor, which is odd, since one would expect that emptying an
empty hash is basically a no-op.
#!/usr/bin/perl
use warnings;
use strict;
$|=1;
use Scalar::Util qw(weaken);
for my $f (1..100000) {
my %H;
for my $id (1..100) {
# weaken( $H{$id} = {} ); # leaks
weaken( $H{$id} = bless {}, 'MyStruct' ); # leaks too
# $H{$id} = bless {}, 'MyStruct'; # no leak
}
}
package MyStruct;
sub DESTROY {
my ($self)=@_;
# %$self=(); # uncomment to make the leak go away
}
__END__
-- Petr Pajas
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=medium
---
This perlbug was built using Perl 5.10.0 - Tue Jul 15 14:37:49 UTC 2008
It is being executed now by Perl 5.10.0 - Tue Jul 15 14:31:57 UTC 2008.
Site configuration information for perl 5.10.0:
Configured by abuild at Tue Jul 15 14:31:57 UTC 2008.
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
Platform:
osname=linux, osvers=2.6.25, archname=x86_64-linux-thread-multi
uname='linux stravinsky 2.6.25 #1 smp 20080210 20:01:04 utc x86_64 x86_64
x86_64 gnulinux '
config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Doptimize=-O2 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -g -Wall -pipe -Accflags=-DPERL_USE_SAFE_PUTENV'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags
='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -g -Wall -pipe',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -DDEBUGGING -fno-strict-aliasing -pipe'
ccversion='', gccversion='4.3.1 20080507 (prerelease) [gcc-4_3-branch
revision 135036]', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib64'
libpth=/lib64 /usr/lib64 /usr/local/lib64
libs=-lm -ldl -lcrypt -lpthread
perllibs=-lm -ldl -lcrypt -lpthread
libc=/lib64/libc-2.8.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.8'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef,
ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/CORE'
cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib64'
Locally applied patches:
---
@INC for perl 5.10.0:
/usr/lib/perl5/5.10.0/x86_64-linux-thread-multi
/usr/lib/perl5/5.10.0
/usr/lib/perl5/site_perl/5.10.0/x86_64-linux-thread-multi
/usr/lib/perl5/site_perl/5.10.0
/usr/lib/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.10.0
/usr/lib/perl5/vendor_perl
.
---
Environment for perl 5.10.0:
HOME=/home/pajas
LANG=cs_CZ.UTF-8
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/opt/kde3/bin:/home/pajas/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin:/usr/lib/qt3/bin
PERL_BADLANG (unset)
SHELL=/bin/bash
Thread Next