develooper Front page | perl.perl5.porters | Postings from March 2007

[perl #41816] call_sv + threads->create leads to leaked scalars

Thread Previous | Thread Next
From:
Mattia Barbon
Date:
March 14, 2007 00:13
Subject:
[perl #41816] call_sv + threads->create leads to leaked scalars
Message ID:
rt-3.6.HEAD-2051-1173828957-1391.41816-75-0@perl.org
# New Ticket Created by  Mattia Barbon 
# Please include the string:  [perl #41816]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41816 >



This is a bug report for perl from mattia.barbon@libero.it,
generated with the help of perlbug 1.35 running under perl v5.8.4.


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

  Hi,
the contrived testcase below causes the message "Scalars leaked: 2";
uncommenting the "undef @_" in the first line of spawn() makes the
symptom go away.  The code seems correct to the best of my XS
knowledge, and I suspect there is something peculiar caused by
the fact that the contents of the Perl argument stack are not
refcounted.  Can anybody suggest a better/less intrusive fix?

threads.pm: v1.59
Perl:       v5.8.4 (Debian stable stock)

Thanks in advance,
Mattia

$ gcc -o foo foo.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
$ ./foo moo.pl
abcdef, 123
1
Scalars leaked: 2
$

=== begin moo.pl
#!/usr/bin/perl -w

use strict;
use threads;

moo();

sub spawn {
    my( $arg1, $arg2 ) = @_; # undef @_;
    print "$arg1, $arg2\n";

    my $test = threads->create( \&my_sub, 1 );
    $test->detach;
    sleep 1;
}

sub my_sub {
    print $_[0], "\n";
}
=== end moo.pl

=== begin foo.c
#include <EXTERN.h>               /* from the Perl distribution     */
#include <perl.h>                 /* from the Perl distribution     */
#include <XSUB.h>

static PerlInterpreter *my_perl;  /***    The Perl interpreter    ***/

XS(XS_moo); /* prototype to pass -Wmissing-prototypes */
XS(XS_moo)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    SV* sv1;
    SV* sv2;

    ENTER ;
    SAVETMPS ;

    sv1 = newSVpv("abcdef", 0);
    sv2 = newSViv(123);
    sv_2mortal(sv1); sv_2mortal(sv2);
    /*SAVEFREESV(sv1); SAVEFREESV(sv2);*/
    /*SAVEMORTALIZESV(sv1); SAVEMORTALIZESV(sv2);*/

    PUSHMARK(SP) ;
    XPUSHs(sv1);
    XPUSHs(sv2);
    PUTBACK ;
    
    call_pv("spawn", G_DISCARD|G_EVAL);
    
    FREETMPS ;
    LEAVE ;
}

static void xs_init (pTHX);
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);

int main(int argc, char **argv, char **env)
{
    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);
    PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
    perl_parse(my_perl, xs_init, argc, argv, (char **)NULL);
    newXS("moo", XS_moo, __FILE__);
    perl_run(my_perl);
    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}

EXTERN_C void
xs_init(pTHX)
{
       char *file = __FILE__;
       /* DynaLoader is a special case */
       newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}
=== end foo.c

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl v5.8.4:

Configured by Debian Project at Wed Mar  9 01:17:01 CET 2005.

Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
  Platform:
    osname=linux, osvers=2.6.10-9-amd64-k8, archname=x86_64-linux-thread-multi
    uname='linux athlon.lowpingbastards.de 2.6.10-9-amd64-k8 #1 sat feb 26 02:04:25 cet 2005 x86_64 gnulinux '
    config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=x86_64-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.4 -Dsitearch=/usr/local/lib/perl/5.8.4 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.4 -Dd_dosuid -des'
    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=define uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='3.3.5 (Debian 1:3.3.5-10)', 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='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
    perllibs=-ldl -lm -lpthread -lc -lcrypt
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libperl.so.5.8.4
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.8.4:
    /home/mbarbon/usr/lib/perl/5.8
    /home/mbarbon/usr/share/perl/5.8
    /etc/perl
    /usr/local/lib/perl/5.8.4
    /usr/local/share/perl/5.8.4
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.8
    /usr/share/perl/5.8
    /usr/local/lib/site_perl
    .

---
Environment for perl v5.8.4:
    HOME=/home/mbarbon
    LANG=it_IT@euro
    LANGUAGE=it_IT
    LC_MESSAGES=en_US
    LD_LIBRARY_PATH=/home/mbarbon/usr/wx/gtk-head/lib:/home/mbarbon/usr/lib:
    LOGDIR (unset)
    PATH=/home/mbarbon/usr/wx/gtk-head/bin:/home/mbarbon/bin:/home/mbarbon/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
    PERL5LIB=/home/mbarbon/usr/lib/perl/5.8:/home/mbarbon/usr/share/perl/5.8:
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About