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

thread constructor with arguments can leak #9969

Closed
p5pRT opened this issue Nov 17, 2009 · 9 comments
Closed

thread constructor with arguments can leak #9969

p5pRT opened this issue Nov 17, 2009 · 9 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 17, 2009

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

Searchable as RT70602$

@p5pRT
Copy link
Author

p5pRT commented Nov 17, 2009

From @ikegami

Created by @ikegami

The following code has Perl saying "Scalars leaked​: 1" numerous times.

----BEGIN CODE----
use strict;
use warnings;

use threads;

sub PINGIT {
  print "PINGIT\n";
  return 0;
}

sub THPING {
  #@​_ = (); # FIX 2
  print "THPING\n";
  my @​th;
  for (1..5) {
  push @​th, threads->create(\&PINGIT);
  }
  $_->join for @​th;
  return 0;
}

{
  my %opts;
  my @​th;
  for (1..2) {
  push @​th, threads->create(\&THPING, \%opts);
  #push @​th, threads->create(\&THPING); # FIX 1
  }
  $_->join for @​th;
}
----END CODE----

----BEGIN OUTPUT----
THPING
PINGIT
PINGIT
THPING
PINGIT
PINGIT
PINGIT
Scalars leaked​: 1
Scalars leaked​: 1
PINGIT
PINGIT
PINGIT
Scalars leaked​: 1
PINGIT
Scalars leaked​: 1
Scalars leaked​: 1
Scalars leaked​: 1
Scalars leaked​: 1
PINGIT
Scalars leaked​: 1
Scalars leaked​: 1
Scalars leaked​: 1
----END OUTPUT----

The leak goes away if no additional arguments are passed to ->create. The
leak goes also goes away if @​_ is emptied inside
the thread functions.

Perl Info

Flags:
    category=library
    severity=medium

The problem is not specific to a version of Perl (reproduced on 5.8.0,
5.8.8, 5.10.0 and 5.10.1).
The problem is not specific to an OS (reproduced on WinXP and Linux).

@p5pRT
Copy link
Author

p5pRT commented Nov 18, 2009

From @jdhedden

The following code has Perl saying "Scalars leaked​: 1" numerous times.

This is another example of a known 'threads' problem involving leaked
scalars caused by temporary stack variables.

Dave Mitchell is has looked at this issue, but does not have a fix.

This bug report and bug reports 41138, 41816 and 66108 (and possibly
others) should be combined.

@p5pRT
Copy link
Author

p5pRT commented Nov 18, 2009

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

@p5pRT
Copy link
Author

p5pRT commented Dec 1, 2009

From @dk

Created by @dk

The code below produces warning "Scalars leaked​: 1". It does so on
blead and 5.10.1, both on win32 and linux.

use threads;
our $X;

sub moo
{
  local $X;
  async {}-> join;
}

moo($X);

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl 5.11.0:

Summary of my perl5 (revision 5 version 11 subversion 0) configuration:
  Commit id: 0f289c68de322445a34feb41ea8f00b7bf9c85de
  Platform:
    osname=linux, osvers=2.6.31-14-generic, archname=i686-linux-thread-multi
    uname='linux wallace 2.6.31-14-generic #48-ubuntu smp fri oct 16 14:04:26 ut
c 2009 i686 gnulinux '
    config_args=''
    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
    useemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.4.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 /usr/lib /usr/lib64
    libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.10.1.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.10.1'
 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'

Characteristics of this binary (from libperl): 
  Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
                        PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_ITHREADS
                        USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API
  Built under linux
  Compiled at Dec  1 2009 16:06:32
  @INC:
    lib
    /usr/local/lib/perl5/site_perl/5.11.0/i686-linux-thread-multi
    /usr/local/lib/perl5/site_perl/5.11.0
    /usr/local/lib/perl5/5.11.0/i686-linux-thread-multi
    /usr/local/lib/perl5/5.11.0
    .

--
Environment for perl 5.10.1:
    HOME=/home/dk
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/dk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/local/site/bin:/usr/local/site/sbin:/home/dk/bin
    PERL_BADLANG (unset)
    SHELL=/usr/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Dec 2, 2009

From @obra

The code below produces warning "Scalars leaked​: 1". It does so on
blead and 5.10.1, both on win32 and linux.

use threads;
our $X;

sub moo
{
local $X;
async {}-> join;
}

moo($X);

And it does on Debian's 5.8.8 (Linux x86) as well.

@p5pRT
Copy link
Author

p5pRT commented Dec 2, 2009

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

@p5pRT
Copy link
Author

p5pRT commented Dec 2, 2009

From @ikegami

On Tue, Dec 1, 2009 at 10​:29 AM, Dmitry Karasik
<perlbug-followup@​perl.org>wrote​:

# New Ticket Created by Dmitry Karasik
# Please include the string​: [perl #70974]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=70974 >

This is a bug report for perl from dmitry@​karasik.eu.org,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
[Please enter your report here]

The code below produces warning "Scalars leaked​: 1". It does so on
blead and 5.10.1, both on win32 and linux.

use threads;
our $X;

sub moo
{
local $X;
async {}-> join;
}

moo($X);

It's a case of a known problem. The workaround is to add @​_=(); in moo().

type 70974.pl
use threads;
our $X;

sub moo
{
  @​_=() if $ARGV[0];
  local $X;
  async {}-> join;
}

moo($X);

perl 70974.pl 0
Scalars leaked​: 1

perl 70974.pl 1

This is the same problem as the one reported in
http​://rt.perl.org/rt3/Ticket/Display.html?id=70602 and others before it.
(Some are listed in a comment to 70602.)

@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'

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

No branches or pull requests

1 participant