Skip Menu |
 
Report information
Id: 70602
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: ikegami [at] adaelis.com
int32 <dmitry [at] karasik.eu.org>
Cc:
AdminCc:

Operating System: (no value)
PatchStatus: (no value)
Severity: low
Type: unknown
Perl Version: (no value)
Fixed In: (no value)



Subject: thread constructor with arguments can leak
Date: Tue, 17 Nov 2009 13:13:31 -0500
To: perlbug [...] perl.org
From: Eric Brine <ikegami [...] adaelis.com>
Download (untitled) / with headers
text/plain 1.5k
This is a bug report for perl from ikegami@adaelis.com,

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

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.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
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).

RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 356b
Show quoted text
> 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.
Subject: threads: scalars leaked
Date: Tue, 1 Dec 2009 16:28:44 +0100
To: perlbug [...] perl.org
From: dmitry [...] karasik.eu.org
Download (untitled) / with headers
text/plain 3.2k
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); [Please do not change anything below this line] ----------------------------------------------------------------- --- 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
Subject: Re: [perl #70974] threads: scalars leaked
Date: Wed, 2 Dec 2009 09:36:04 -0500
To: perl5-porters [...] perl.org
From: Jesse Vincent <jesse [...] fsck.com>
Download (untitled) / with headers
text/plain 276b
Show quoted text
> 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.
Download signature.asc
application/pgp-signature 197b

Message body not shown because it is not plain text.

CC: dmitry [...] karasik.eu.org
Subject: Re: [perl #70974] threads: scalars leaked
Date: Wed, 2 Dec 2009 14:17:52 -0500
To: perl5-porters [...] perl.org, perlbug-followup [...] perl.org
From: Eric Brine <ikegami [...] adaelis.com>
Download (untitled) / with headers
text/plain 1.1k
On Tue, Dec 1, 2009 at 10:29 AM, Dmitry Karasik <perlbug-followup@perl.org>wrote: Show quoted text
> # 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(). Show quoted text
>type 70974.pl
use threads; our $X; sub moo { @_=() if $ARGV[0]; local $X; async {}-> join; } moo($X); Show quoted text
>perl 70974.pl 0
Scalars leaked: 1 Show quoted text
>perl 70974.pl 1
Show quoted text
>
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.)
Fixed in blead with e81cd4d2c506bfc28460d324d94b81010f5ee455


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org