Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

perl_parse memory leak with dynamic loaded modules

3 views
Skip to first unread message

James Shirley

unread,
Apr 14, 2010, 9:05:05 PM4/14/10
to per...@perl.org
Hi, I'm trying to write a persistent perl daemon, but have noticed what looks like a memory leak, with perl_parse.

It only seems to occur once dynamic loading of perl modules is enabled, here is my test kit:

code in showtime.c:

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

EXTERN_C void xs_init(pTHX);

int main(int argc, char **argv, char **env) {
        char *args[] = { NULL };
        PERL_SYS_INIT3(&argc,&argv,&env);
        int j;
        for(j=100000; j>0; --j) {
                PerlInterpreter *my_perl = perl_alloc();
                perl_construct(my_perl);

                perl_parse(my_perl, xs_init, argc, argv, NULL);
                PL_exit_flags |= PERL_EXIT_DESTRUCT_END;

                perl_destruct(my_perl);
                perl_free(my_perl);
        }
        PERL_SYS_TERM();
}

to compile:

# perl -MExtUtils::Embed -e xsinit
# cc -c perlxsi.c `perl -MExtUtils::Embed -e ccopts`
# cc -c showtime.c `perl -MExtUtils::Embed -e ccopts`
# cc -o showtime perlxsi.o showtime.o `perl -MExtUtils::Embed -e ldopts`

To run:

# ./showtime -e "use Time::HiRes;" &
# watch -d ps u $!

Notice RSS size keeps on getting larger, 20k/sec
Works with other modules aswell

# perl -v

This is perl, v5.10.0 built for i486-linux-gnu-thread-multi

This wouldn't be a problem normally as I could simply dump the process after x calls, however writing this into a pthreaded app makes it very hard to dump & recreate the process.

I've run valgrind over it, and it cannot find any memory leaks..

Any help would be much appreciated..

Cheers

James Shirley

Reini Urban

unread,
Jun 7, 2010, 1:19:29 PM6/7/10
to ji...@conceptual.com.au, per...@perl.org
James Shirley schrieb:

> Hi, I'm trying to write a persistent perl daemon, but have noticed what
> looks like a memory leak, with perl_parse.
>
> It only seems to occur once dynamic loading of perl modules is enabled,
> here is my test kit:
...

> # ./showtime -e "use Time::HiRes;" &
> # watch -d ps u $!
>
> Notice RSS size keeps on getting larger, 20k/sec
> Works with other modules aswell
> I've run valgrind over it, and it cannot find any memory leaks..
> Any help would be much appreciated..

I believe DynaLoader:dl_unload_file is never called implicitly in the
module destructor, so you have to do that manually.

something like:
record the so in your object, and
sub DESTROY {
DynaLoader::dl_unload_file($shift->your_so)
if defined (&DynaLoader::dl_unload_file);
}
--
Reini Urban
http://phpwiki.org/ http://murbreak.at/

0 new messages