Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stash <-> @ISA circular ref #11420

Open
p5pRT opened this issue Jun 13, 2011 · 4 comments
Open

stash <-> @ISA circular ref #11420

p5pRT opened this issue Jun 13, 2011 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 13, 2011

Migrated from rt.perl.org#92708 (status was 'new')

Searchable as RT92708$

@p5pRT
Copy link
Author

p5pRT commented Jun 13, 2011

From @cpansprout

There is a circular reference between stashes and their @​ISA arrays. The @​ISA arrays’ isa magic contains refcounted pointers to the stashes to which they belong. That means a script like this leaks memory​:

$ perl5.14.0 -e 'warn $$; while(1){ @​{"foo​::bar​::ISA"} = "main"; use Symbol; Symbol​::delete_package("foo")}'

Should the isa magic be using weak references?

The relevant code is in sv.c​:S_glob_assign_glob (search for ‘if(mro_changes == 2)’), sv.c​:S_glob_assign_ref (at the end of the function) and, of course, in mg.c​:Perl_magic_clearisa.


Flags​:
  category=core
  severity=low


Site configuration information for perl 5.14.0​:

Configured by sprout at Wed May 11 13​:45​:58 PDT 2011.

Summary of my perl5 (revision 5 version 14 subversion 0) configuration​:
  Snapshot of​: eb70bb4
  Platform​:
  osname=darwin, osvers=10.5.0, archname=darwin-thread-multi-2level
  uname='darwin pint.local 10.5.0 darwin kernel version 10.5.0​: fri nov 5 23​:20​:39 pdt 2010; root​:xnu-1504.9.17~1release_i386 i386 '
  config_args='-Dusedevel -de -Duseithreads -Doptimize=-g'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=undef, use64bitall=undef, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
  optimize='-g',
  cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.2.1 (Apple Inc. build 5664)', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /usr/lib
  libs=-ldbm -ldl -lm -lutil -lc
  perllibs=-ldl -lm -lutil -lc
  libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector'

Locally applied patches​:
  RC3


@​INC for perl 5.14.0​:
  /usr/local/lib/perl5/site_perl/5.14.0/darwin-thread-multi-2level
  /usr/local/lib/perl5/site_perl/5.14.0
  /usr/local/lib/perl5/5.14.0/darwin-thread-multi-2level
  /usr/local/lib/perl5/5.14.0
  /usr/local/lib/perl5/site_perl
  .


Environment for perl 5.14.0​:
  DYLD_LIBRARY_PATH (unset)
  HOME=/Users/sprout
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/bin​:/bin​:/usr/sbin​:/sbin​:/usr/local/bin​:/usr/X11/bin​:/usr/local/bin
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Feb 21, 2012

From jtbraun@CPAN.org

This is a bug report for perl from jtbraun@​CPAN.org,
generated with the help of perlbug 1.39 running under perl 5.14.2.

# Test case, see below __END__ for full description
use warnings;
use strict;

foreach my $erase (1,0) {
  foreach my $varname (qw(OTHER ISA)) {
  my $lastmem = "";
  for my $i ( 1 .. 512 ) {
  my $namespace = "namespace$i";
  {
  no strict 'refs';
  # create the array in the target package
  @​{"Acme​::Test​::${namespace}​::$varname"} = ('a'x512);
  # optionally "erase" the array
  if ($erase) {
  @​{"Acme​::Test​::${namespace}​::$varname"} = ()
  }
  # delete the stack for the package
  delete $Acme​::Test​::{$namespace.'​::'};
  }

  # Get the current process's memory usage (probably only
  # works on Linux, I'm using "procps version 3.2.8"
  my $mem = `ps h -o size $$`;
  chomp($mem);
  $mem = sprintf( "%.2f", $mem / 1024 );

  # Print out memory usage if it's changed
  if ($lastmem ne $mem) {
  printf "%3d :​: \@​%-10s (%serased) :​: %s\n",
  $i, $varname, $erase ? '' : 'not ', $mem;
  $lastmem = $mem;
  }
  }
  }
}

__END__

The test above creates an array variable named @​OTHER or @​ISA in the
package "Acme​::Test​::namespace$i" for $i in 1..512.

Immediately after the package is created, the stash for that namespace
is deleted (which should delete the created array).

Then the perl process's memory is queried via the external 'ps'
program, and printed if it's grown.

The result​: non-empty @​ISA arrays appear to leak memory. If the @​ISA
array is explcitly cleared prior to deleting the package's stash, the
@​ISA array no longer appears to leak.

Also included below is some example output, and some Test​::LeakTrace
output from one of the leaking iterations.

Perhaps the special treatment of @​ISA in S_gv_magicalize_isa() from
gv.c is the cause of the leak? %OVERLOAD didn't seem to have the same
problem, but perhaps it is handled differently?

The output of the above test from an example run on my machine. Note
that memory only increases on the test run for @​ISA which does not
explicitly clear out the array before stash deletion.

  1 :​: @​OTHER (erased) :​: 0.58
  1 :​: @​ISA (erased) :​: 0.58
  1 :​: @​OTHER (not erased) :​: 0.58
  1 :​: @​ISA (not erased) :​: 0.58
  80 :​: @​ISA (not erased) :​: 0.71
  81 :​: @​ISA (not erased) :​: 0.70
269 :​: @​ISA (not erased) :​: 0.83
270 :​: @​ISA (not erased) :​: 0.82
457 :​: @​ISA (not erased) :​: 0.95
458 :​: @​ISA (not erased) :​: 0.94

An example output from Test​::LeakTrace's​:
  leaktrace {BLOCK} -verbose

leaked SCALAR(0x9e34ec0) from leak2.pl line 17.
  16​: leaktrace {
  17​: @​{"Acme​::Test​::${namespace}​::$varname"} =
('a'x512);
  18​: delete $Acme​::Test​::{$namespace.'​::'};
SV = PVMG(0x9e2f248) at 0x9e34ec0
  REFCNT = 1
  FLAGS = (SMG,POK,pPOK)
  IV = 0
  NV = 0
  PV = 0x9e3cd18
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\0
  CUR = 512
  LEN = 516
  MAGIC = 0x9e3cf20
  MG_VIRTUAL = 0x817e920
  MG_TYPE = PERL_MAGIC_isaelem(i)
  MG_FLAGS = 0x02
  REFCOUNTED
  MG_OBJ = 0x9e34ea0
  SV = PVAV(0x9e372fc) at 0x9e34ea0
  REFCNT = 1
  FLAGS = (SMG,RMG)
  MAGIC = 0x9d9f9d8
  MG_VIRTUAL = &PL_vtbl_isa
  MG_TYPE = PERL_MAGIC_isa(I)
  MG_OBJ = 0x9e34e90
  ARRAY = 0x9d9f9f8
  FILL = 0
  MAX = 3
  ARYLEN = 0x0
  FLAGS = (REAL)
  Elt No. 0
  SV = PVMG(0x9e2f248) at 0x9e34ec0
  REFCNT = 1
  FLAGS = (SMG,POK,pPOK)
  IV = 0
  NV = 0
  PV = 0x9e3cd18
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\0
  CUR = 512
  LEN = 516
  MAGIC = 0x9e3cf20
  MG_VIRTUAL = 0x817e920
  MG_TYPE = PERL_MAGIC_isaelem(i)
  MG_FLAGS = 0x02
  REFCOUNTED
  MG_OBJ = 0x9e34ea0
  SV = PVAV(0x9e372fc) at 0x9e34ea0
  REFCNT = 1
  FLAGS = (SMG,RMG)
  MAGIC = 0x9e3da68
  MG_VIRTUAL = &PL_vtbl_arylen_p
  MG_TYPE = PERL_MAGIC_arylen_p(@​)
  MG_FLAGS = 0x02
  REFCOUNTED
  MAGIC = 0x9d9f9d8
  MG_VIRTUAL = &PL_vtbl_isa
  MG_TYPE = PERL_MAGIC_isa(I)
  MG_OBJ = 0x9e34e90
  ARRAY = 0x9d9f9f8
  FILL = 0
  MAX = 3
  ARYLEN = 0x0
  FLAGS = (REAL)
leaked ARRAY(0x9e34ea0) from leak2.pl line 17.
  16​: leaktrace {
  17​: @​{"Acme​::Test​::${namespace}​::$varname"} =
('a'x512);
  18​: delete $Acme​::Test​::{$namespace.'​::'};
SV = PVAV(0x9e372fc) at 0x9e34ea0
  REFCNT = 1
  FLAGS = (SMG,RMG)
  MAGIC = 0x9e3da68
  MG_VIRTUAL = &PL_vtbl_arylen_p
  MG_TYPE = PERL_MAGIC_arylen_p(@​)
  MG_FLAGS = 0x02
  REFCOUNTED
  MAGIC = 0x9d9f9d8
  MG_VIRTUAL = &PL_vtbl_isa
  MG_TYPE = PERL_MAGIC_isa(I)
  MG_OBJ = 0x9e34e90
  ARRAY = 0x9d9f9f8
  FILL = 0
  MAX = 3
  ARYLEN = 0x0
  FLAGS = (REAL)
  Elt No. 0
  SV = PVMG(0x9e2f248) at 0x9e34ec0
  REFCNT = 1
  FLAGS = (SMG,POK,pPOK)
  IV = 0
  NV = 0
  PV = 0x9e3cd18
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\0
  CUR = 512
  LEN = 516
  MAGIC = 0x9e3cf20
  MG_VIRTUAL = 0x817e920
  MG_TYPE = PERL_MAGIC_isaelem(i)
  MG_FLAGS = 0x02
  REFCOUNTED
  MG_OBJ = 0x9e34ea0
  SV = PVAV(0x9e372fc) at 0x9e34ea0
  REFCNT = 1
  FLAGS = (SMG,RMG)
  MAGIC = 0x9e3da68
  MG_VIRTUAL = &PL_vtbl_arylen_p
  MG_TYPE = PERL_MAGIC_arylen_p(@​)
  MG_FLAGS = 0x02
  REFCOUNTED
  MAGIC = 0x9d9f9d8
  MG_VIRTUAL = &PL_vtbl_isa
  MG_TYPE = PERL_MAGIC_isa(I)
  MG_OBJ = 0x9e34e90
  ARRAY = 0x9d9f9f8
  FILL = 0
  MAX = 3
  ARYLEN = 0x0
  FLAGS = (REAL)
  Elt No. 0
  SV = PVMG(0x9e2f248) at 0x9e34ec0
  REFCNT = 1
  FLAGS = (SMG,POK,pPOK)
  IV = 0
  NV = 0
  PV = 0x9e3cd18
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\0
  CUR = 512
  LEN = 516
  MAGIC = 0x9e3cf20
  MG_VIRTUAL = 0x817e920
  MG_TYPE = PERL_MAGIC_isaelem(i)
  MG_FLAGS = 0x02
  REFCOUNTED
  MG_OBJ = 0x9e34ea0
  SV = PVAV(0x9e372fc) at 0x9e34ea0
  REFCNT = 1
  FLAGS = (SMG,RMG)
  MAGIC = 0x9e3da68
  MG_VIRTUAL = &PL_vtbl_arylen_p
  MG_TYPE = PERL_MAGIC_arylen_p(@​)
  MG_FLAGS = 0x02
  REFCOUNTED
  MAGIC = 0x9d9f9d8
  MG_VIRTUAL = &PL_vtbl_isa
  MG_TYPE = PERL_MAGIC_isa(I)
  MG_OBJ = 0x9e34e90
  ARRAY = 0x9d9f9f8
  FILL = 0
  MAX = 3
  ARYLEN = 0x0
  FLAGS = (REAL)


Flags​:
  category=core
  severity=medium


Site configuration information for perl 5.14.2​:

Configured by jtbraun at Thu Dec 1 01​:10​:27 PST 2011.

Summary of my perl5 (revision 5 version 14 subversion 2) configuration​:

  Platform​:
  osname=linux, osvers=3.0.0-13-generic, archname=i686-linux
  uname='linux pedafly 3.0.0-13-generic #22-ubuntu smp wed nov 2
13​:25​:36 utc 2011 i686 i686 i386 gnulinux '
  config_args='-de
-Dprefix=/home/jtbraun/perl5/perlbrew/perls/perl-5.14.2'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=undef, usemultiplicity=undef
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=undef, use64bitall=undef, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2',
  cppflags='-fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include'
  ccversion='', gccversion='4.6.1', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=4, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /lib/i386-linux-gnu /lib/../lib
/usr/lib/i386-linux-gnu /usr/lib/../lib /lib /usr/lib
  libs=-lnsl -ldl -lm -lcrypt -lutil -lc
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
  libc=, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.13'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib
-fstack-protector'

Locally applied patches​:


@​INC for perl 5.14.2​:
  /home/jtbraun/perl5/CPAN/lib/perl5/i686-linux
  /home/jtbraun/perl5/CPAN/lib/perl5
  /home/jtbraun/whome/lib/perl5
 
/home/jtbraun/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2/i686-linux
  /home/jtbraun/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2
  /home/jtbraun/perl5/perlbrew/perls/perl-5.14.2/lib/5.14.2/i686-linux
  /home/jtbraun/perl5/perlbrew/perls/perl-5.14.2/lib/5.14.2
  .


Environment for perl 5.14.2​:
  HOME=/home/jtbraun
  LANG=en_US.UTF-8
  LANGUAGE=en_US​:en
  LC_COLLATE=en_US.UTF-8
  LC_CTYPE=en_US.UTF-8
  LC_MESSAGES=en_US.UTF-8
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
 
PATH=/home/jtbraun/perl5/perlbrew/bin​:/home/jtbraun/perl5/perlbrew/perls/perl-5.14.2/bin​:/home/jtbraun/whome/bin/linux​:/usr/lib/lightdm/lightdm​:/usr/local/sbin​:/usr/local/bin​:/usr/sbin​:/usr/bin​:/sbin​:/bin​:/usr/games​:/home/jtbraun/perl5/CPAN/bin
 
PERL5LIB=/home/jtbraun/perl5/CPAN/lib/perl5​:/home/jtbraun/whome/lib/perl5
  PERLBREW_BASHRC_VERSION=0.33
  PERLBREW_HOME=/home/jtbraun/.perlbrew
  PERLBREW_MANPATH=/home/jtbraun/perl5/perlbrew/perls/perl-5.14.2/man
 
PERLBREW_PATH=/home/jtbraun/perl5/perlbrew/bin​:/home/jtbraun/perl5/perlbrew/perls/perl-5.14.2/bin
  PERLBREW_PERL=perl-5.14.2
  PERLBREW_ROOT=/home/jtbraun/perl5/perlbrew
  PERLBREW_VERSION=0.41
  PERL_BADLANG (unset)
  PERL_CPANM_OPT=--prompt --reinstall -l ~/perl5/CPAN
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Feb 21, 2012

From bitcard@spamwagon.com

On closer inspection, this appears to be a duplicate of #92708? Sorry
for the repeat submission.

Jeremy

@p5pRT
Copy link
Author

p5pRT commented Feb 21, 2012

The RT System itself - Status changed from 'new' to 'open'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants