develooper Front page | perl.perl5.porters | Postings from July 2001

perl_clone leaks

Thread Next
From:
Doug MacEachern
Date:
July 11, 2001 09:19
Subject:
perl_clone leaks
Message ID:
Pine.LNX.4.21.0107110916290.11688-100000@mako.covalent.net
the following program does not leak with 5.6.1, with bleedperl leaks,
example:
% ./clone_leak -MCGI -e0
Scalars leaked: -4
Scalars leaked: 4
  PID   VSZ COMMAND
 3673  4428 clone_leak
...
Scalars leaked: -4
Scalars leaked: 4
  PID   VSZ COMMAND
 3673  4676 clone_leak

compile with:
% gcc -o clone_leak clone_leak.c `perl -MExtUtils::Embed -e ccopts -e ldopts`

#define PERL_NO_GET_CONTEXT

#include <EXTERN.h>
#include <perl.h>

void xs_init (pTHXo);
void boot_DynaLoader (pTHXo_ CV* cv);

void xs_init(pTHXo)
{
    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__);
}

static void destroy_clone(PerlInterpreter *parent, PerlInterpreter *clone)
{
    dTHXa(clone);

    PERL_SET_CONTEXT(clone);

    PL_perl_destruct_level = 2;
    perl_destruct(clone); 
    perl_free(clone); 

    PERL_SET_CONTEXT(parent);
}

int main(int argc, char **argv, char **env)
{
    int i;
    char ps[256];

    sprintf(ps, "ps -o 'pid,vsz,comm' -p %d", (int)getpid());

    for (i=1; i<=10; i++) {
        PerlInterpreter *clone;
        PerlInterpreter *my_perl = perl_alloc();

        perl_construct(my_perl);

        perl_parse(my_perl, xs_init, argc, argv, env);

        perl_run(my_perl); 

        clone = perl_clone(my_perl, 0);
        destroy_clone(my_perl, clone);

        PL_perl_destruct_level = 2;
        perl_destruct(my_perl); 
        perl_free(my_perl); 

        system(ps);
    }

    return 1;
}


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