develooper 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
Petr Pajas
November 20, 2008 06:13
[perl #60680] Perl 5.10 memory leak: 'use Scalar::Util qw(weaken); weaken({}) while 1'
Message ID:
# New Ticket Created by  Petr Pajas 
# Please include the string:  [perl #60680]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.36 running under perl 5.10.0.

[Please enter your report here]


the following one-liner leaks as hell with Perl 5.10, but runs fine with Perl 

   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.

use warnings;
use strict;
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;

  my ($self)=@_;
  # %$self=();   # uncomment to make the leak go away


  -- Petr Pajas

[Please do not change anything below this line]
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:
    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
    cc='cc', ccflags 
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', 
    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/, so=so, useshrplib=true,
  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:

Environment for perl 5.10.0:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About