isemenov has asked for the wisdom of the Perl Monks concerning the following question:

I create a simple perl embedding code (copy-paste from documentation):
#include <EXTERN.h> #include <perl.h> static PerlInterpreter * my_perl = 0; int main(int argc, char **argv, char **env) { PERL_SYS_INIT3( &argc, &argv, &env ); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, 0, argc, argv, 0); perl_run(my_perl); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }

Command line: ./test -e 'print "Hello, world!"'
Works fine, but valgrind report leaks:

==10428== 116 bytes in 15 blocks are definitely lost in loss record 1 +of 2 ==10428== at 0x4A1BDEB: malloc (vg_replace_malloc.c:207) ==10428== by 0x497945: Perl_safesysmalloc (util.c:78) ==10428== by 0x4996C3: Perl_savepvn (util.c:789) ==10428== by 0x42BC24: Perl_gv_fetchpv (gv.c:754) ==10428== by 0x4260CF: S_init_main_stash (perl.c:3510) ==10428== by 0x42034F: S_parse_body (perl.c:1657) ==10428== by 0x420020: perl_parse (perl.c:1598) ==10428== by 0x41D2A6: main (tiny.cpp:12) LEAK SUMMARY: ==10428== definitely lost: 116 bytes in 15 blocks. ==10428== possibly lost: 0 bytes in 0 blocks. ==10428== still reachable: 1,109 bytes in 17 blocks. ==10428== suppressed: 0 bytes in 0 blocks.

1225 leaked bytes on simplest example - not very good. Any ideas?

P.S.: valgrind 3.3.0 - latest release, perl 5.8.8

Replies are listed 'Best First'.
Re: Leaks while embedding perl (Perl Internals References)
by eyepopslikeamosquito (Archbishop) on Mar 13, 2008 at 11:19 UTC