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

$_ leaks under threads #8719

Closed
p5pRT opened this issue Dec 26, 2006 · 8 comments
Closed

$_ leaks under threads #8719

p5pRT opened this issue Dec 26, 2006 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 26, 2006

Migrated from rt.perl.org#41138 (status was 'resolved')

Searchable as RT41138$

@p5pRT
Copy link
Author

p5pRT commented Dec 26, 2006

From @jdhedden

Created by @jdhedden

Here's the test script​:

use threads;

for (1..1) {
  leak($_); # Produces "Scalars leaked​: 1"
  #leak(); # No leaks
}

sub leak
{
  for (1..1) {
  threads->create(sub {})->join();
  }
}

This produces the same result in blead.

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.8.8:

Configured by Jerry at Wed Dec 20 08:14:01 EST 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=cygwin, osvers=1.5.23(0.15642),
archname=cygwin-thread-multi-64int
    uname='cygwin_nt-5.0 pn100-02-2-054p 1.5.23(0.15642) 2006-12-19
10:52 i686 cygwin '
    config_args='-de -Duse64bitint -Dusethreads -Uusemymalloc
-Dnoextensions=attrs IPC/SysV -A define:optimize=-O3 -pipe
-funit-at-a-time -mtune=pentium4m -march=pentium4 -mfpmath=sse
-mieee-fp -mmmx -msse -msse2 -A define:ld=/usr/bin/ld2 -A
append:ccflags= -DPERL_DONT_CREATE_GVSV -DNO_MATHOMS'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -DPERL_DONT_CREATE_GVSV
-DNO_MATHOMS -fno-strict-aliasing -pipe -Wdeclaration-after-statement',
    optimize='-O3 -pipe -funit-at-a-time -mtune=pentium4m
-march=pentium4 -mfpmath=sse -mieee-fp -mmmx -msse -msse2',
    cppflags='-DPERL_USE_SAFE_PUTENV -DPERL_DONT_CREATE_GVSV
-DNO_MATHOMS -fno-strict-aliasing -pipe -Wdeclaration-after-statement'
    ccversion='', gccversion='3.4.4 (cygming special, gdc 0.12, using
dmd 0.125)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8,
Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='/usr/bin/ld2', ldflags =' -s -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /lib
    libs=-lgdbm -ldb -ldl -lcrypt -lgdbm_compat
    perllibs=-ldl -lcrypt -lgdbm_compat
    libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' -s'
    cccdlflags=' ', lddlflags=' -s -L/usr/local/lib'

Locally applied patches:
    MAINT28213
    29163


@INC for perl v5.8.8:
    /usr/lib/perl5/5.8/cygwin
    /usr/lib/perl5/5.8
    .


Environment for perl v5.8.8:
    CYGWIN=server ntsec
    HOME=/home/jhedden
    LANG=C
    LANGUAGE=C
    LC_ALL=C
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
   
PATH=/home/jhedden/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/c/Perl/bin:/c/djgpp/bin:/c/Program
Files/WiX:/c/Program Files/nant-0.85-rc3/bin:/c/Program
Files/apache-ant-1.6.3/bin:/c/j2sdk1.4.2_08/bin:/c/Program
Files/Documentum/Shared:/c/blp/API:/c/oracle/ora92/bin:/c/Program
Files/Oracle/jre/1.3.1/bin:/c/Program
Files/Oracle/jre/1.1.8/bin:/c/WINNT/system32:/c/WINNT:/c/WINNT/system32/WBEM:/c/Program
Files/cvsnt:/c/Program Files/QuickTime/QTSystem/:/c/dev-cpp/bin/:.
    PERLIO=perlio
    PERL_BADLANG (unset)
    SHELL (unset)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2007

From @iabyn

On Tue, Dec 26, 2006 at 07​:52​:27AM -0800, jdhedden @​ 1979. usna. com wrote​:

Here's the test script​:

use threads;

for (1..1) {
leak($_); # Produces "Scalars leaked​: 1"
#leak(); # No leaks
}

sub leak
{
for (1..1) {
threads->create(sub {})->join();
}
}

This can be reduced to​:

  use threads;

  leak($x);

  sub leak
  {
  local $x;
  threads->create(sub {})->join();
  }

(so it's not specific to $_). It occurs, because at the point the thread
is cloned, the saved $x is referenced from​:
  * the save stack
  * the @​_ array​: which is not refcnted

For threads creation, the save stack isn't duplicated, so the saved $x is
duplicated only via @​_, which isn't refcnted, so the cloned $x gets
created with refcnt=0 and hangs around until thread exit.

Can't see an easy way to fix this.

--
My get-up-and-go just got up and went.

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2007

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

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2007

From @nwc10

On Sun, Jan 07, 2007 at 09​:23​:28PM +0000, Dave Mitchell wrote​:

This can be reduced to​:

use threads;

leak\($x\);

sub leak
\{
local $x;
threads\->create\(sub \{\}\)\->join\(\);
\}

(so it's not specific to $_). It occurs, because at the point the thread
is cloned, the saved $x is referenced from​:
* the save stack
* the @​_ array​: which is not refcnted

For threads creation, the save stack isn't duplicated, so the saved $x is
duplicated only via @​_, which isn't refcnted, so the cloned $x gets
created with refcnt=0 and hangs around until thread exit.

Can't see an easy way to fix this.

For things that are duplicated by the no_inc variants (so implicitly start
out with a reference count of zero in the ptr_table that maps parent to child),
would it work to instead create them with a reference count of one, and
place an entry on the save stack to free that reference?

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2007

From guest@guest.guest.xxxxxxxx

On Sun Jan 07 14​:17​:12 2007, nicholas wrote​:

On Sun, Jan 07, 2007 at 09​:23​:28PM +0000, Dave Mitchell wrote​:

This can be reduced to​:

use threads;

leak\($x\);

sub leak
\{
local $x;
threads\->create\(sub \{\}\)\->join\(\);
\}

(so it's not specific to $_). It occurs, because at the point the
thread
is cloned, the saved $x is referenced from​:
* the save stack
* the @​_ array​: which is not refcnted

For threads creation, the save stack isn't duplicated, so the saved
$x is
duplicated only via @​_, which isn't refcnted, so the cloned $x gets
created with refcnt=0 and hangs around until thread exit.

Can't see an easy way to fix this.

For things that are duplicated by the no_inc variants (so implicitly
start
out with a reference count of zero in the ptr_table that maps parent
to child),
would it work to instead create them with a reference count of one,
and
place an entry on the save stack to free that reference?

Nicholas Clark

I have modified the test script and seems to stop this leak​:
sub leak
{
  my $arg = shift; #no leak

  for (1..1)
  {
  threads->create(sub {})->join();
  }
}

Does anyone know what time frame this problem will be fixed?

@p5pRT
Copy link
Author

p5pRT commented Jan 11, 2010

From @iabyn

fixed in blead with e81cd4d

@p5pRT
Copy link
Author

p5pRT commented Jan 11, 2010

@iabyn - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed Jan 11, 2010
@p5pRT
Copy link
Author

p5pRT commented Jan 11, 2010

From @jdhedden

On Mon, Jan 11, 2010 at 07​:54, Dave Mitchell via RT
<perlbug-followup@​perl.org> wrote​:

According to our records, your request regarding
 "$_ leaks under threads"
has been resolved.

If you have any further questions or concerns, please respond to this message.

For other topics, please create a new ticket.

Please don't feel obligated to say "Thanks" or "Kudos" or "I owe you a beer" -- if you respond to this message it will reopen the ticket. If you must, please send email directly to the person who handled your ticket, and not to the tracking system.

<URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=41138 >

This fix also fixes #34342.

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

1 participant