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

threads leak when detached #10887

Closed
p5pRT opened this issue Dec 9, 2010 · 7 comments
Closed

threads leak when detached #10887

p5pRT opened this issue Dec 9, 2010 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 9, 2010

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

Searchable as RT80484$

@p5pRT
Copy link
Author

p5pRT commented Dec 9, 2010

From mmaslano@redhat.com

Created by marca@localhost6.localdomain6

Perl appears to leak memory when threads are created and then
detached.

Version​: found on 5.8.8, but it's also reproducible with 5.8.9

Test case​:
use threads;

sub ThreadRoutine {}

while (1) {
  $thread = threads->new(\&ThreadRoutine);
  $thread->join;
}

It can be tested with attached script measure.pl. After applying
patch - leak.patch, no leaks were observed.

Perl Info

Flags:
    category=core
    severity=medium

This perlbug was built using Perl 5.12.2 in the Fedora build system.
It is being executed now by Perl 5.12.2 - Wed Dec  1 13:04:08 UTC 2010.

Site configuration information for perl 5.12.2:

Configured by Red Hat, Inc. at Wed Dec  1 13:04:08 UTC 2010.

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

  Platform:
    osname=linux, osvers=2.6.32-72.el6.bz634452.x86_64,
archname=x86_64-linux-thread-multi
    uname='linux x86-19.phx2.fedoraproject.org
2.6.32-72.el6.bz634452.x86_64 #1 smp fri sep 17 06:52:25 edt 2010 x86_64
x86_64 x86_64 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m64 -mtune=generic
-Dccdlflags=-Wl,--enable-new-dtags -DDEBUGGING=-g -Dversion=5.12.2
-Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red
Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local
-Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5
-Dprivlib=/usr/share/perl5 -Dvendorlib=/usr/share/perl5
-Darchlib=/usr/lib64/perl5 -Dvendorarch=/usr/lib64/perl5
-Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64
/usr/lib64 -Duseshrplib -Dusethreads -Duseithreads
-Dusedtrace=/usr/bin/dtrace -Duselargefiles -Dd_semctl_semun -Di_db
-Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio
-Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly
-Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto
-Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto
-Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin
-Dotherlibdirs=/usr/local/lib64/perl5/site_perl/5.10.0/x86_64-linux-thread-multi:/usr/local/lib/perl5/site_perl/5.10.0:/usr/lib64/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi:/usr/lib/perl5/vendor_perl:/usr/lib/perl5/site_perl'
    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
  Compiler:
    cc='gcc', 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 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.5.1 20100924 (Red Hat 4.5.1-4)',
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',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector'
    libpth=/usr/local/lib64 /lib64 /usr/lib64
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread
-lc -lgdbm_compat
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.12.90'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef,
ccdlflags='-Wl,--enable-new-dtags -Wl,-rpath,/usr/lib64/perl5/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m64 -mtune=generic'

Locally applied patches:




@INC for perl 5.12.2:
    /usr/local/lib64/perl5
    /usr/local/share/perl5
    /usr/lib64/perl5
    /usr/share/perl5
    /usr/lib64/perl5
    /usr/share/perl5
    /usr/local/lib64/perl5/site_perl/5.10.0/x86_64-linux-thread-multi
    /usr/local/lib/perl5/site_perl/5.10.0
    /usr/lib64/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/site_perl
    .


Environment for perl 5.12.2:
    HOME=/home/marca
    LANG=en_US.UTF-8
    LANGUAGE=
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
   
PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/usr/sbin:/sbin:/home/marca/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


@p5pRT
Copy link
Author

p5pRT commented Dec 9, 2010

From mmaslano@redhat.com

measure.pl

@p5pRT
Copy link
Author

p5pRT commented Dec 9, 2010

From mmaslano@redhat.com

leak.patch
diff --git a/hv.c b/hv.c
index 0721a14..f581cdb 100644
--- a/hv.c
+++ b/hv.c
@@ -1624,6 +1624,7 @@
 	/* FIXME - strlen HvNAME  */
         if(PL_stashcache)
 	    hv_delete(PL_stashcache, name, strlen(name), G_DISCARD);
+	Safefree(HvNAME(hv));
 	hv_name_set(hv, Nullch, 0, 0);
     }
     xhv->xhv_max   = 7;	/* HvMAX(hv) = 7 (it's a normal hash) */

@p5pRT
Copy link
Author

p5pRT commented Dec 14, 2010

From @iabyn

On Thu, Dec 09, 2010 at 08​:08​:42AM -0800, Marcela Maslanova wrote​:

Perl appears to leak memory when threads are created and then
detached.

But your test code does join rather than detach.

Version​: found on 5.8.8, but it's also reproducible with 5.8.9

But it's fixed in 5.10.0 onwards, and your patch appears to be against
version 5.8.8, which is almost 5 years old and is unsupported. So, thanks
for the effort, but it appears to have been wasted :-(.

Test case​:
use threads;

sub ThreadRoutine {}

while (1) {
$thread = threads->new(\&ThreadRoutine);
$thread->join;
}

It can be tested with attached script measure.pl. After applying
patch - leak.patch, no leaks were observed.

--
Overhead, without any fuss, the stars were going out.
  -- Arthur C Clarke

@p5pRT
Copy link
Author

p5pRT commented Dec 14, 2010

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

@p5pRT
Copy link
Author

p5pRT commented Jan 6, 2011

From mmaslano@redhat.com

My mistake. The original report was about detach, but it was seen better
on test case in my original post.

Original test case (with detach)​:
  #!/usr/bin/perl
  use threads;
  my $subref = sub { 42; };
  my $t;
  while(1) {
  $t=threads->new($subref);
  $t->detach();
  }

I hope this fix could help users on 5.8.x, but feel free to close it if
it's not supported any more.

@p5pRT
Copy link
Author

p5pRT commented Apr 25, 2011

@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
Projects
None yet
Development

No branches or pull requests

1 participant