Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

memory leak <<<PerlEmbed

by jithoosin (Scribe)
on Dec 21, 2005 at 13:24 UTC ( [id://518299]=perlquestion: print w/replies, xml ) Need Help??

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

Hi monks,

There is section called "Fiddling with the Perl stack from your C program" in perlembed. In it there is a perl code for integer exponentiation which is called from C function. Actually that code works pretty fine.
My doubt is that when i just added use DBI; to the perl code and exectuted the C code i am getting error
free(): invalid pointer 0x804c6b8!
How could i avoid it. I am also getting this error in some other programs also. The C code and perl code are given below
#include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); EXTERN_C void xs_init(pTHX) { char *file = __FILE__; dXSUB_SYS; /* DynaLoader is a special case */ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); } static void PerlPower(int a, int b) { dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSViv(a))); XPUSHs(sv_2mortal(newSViv(b))); PUTBACK; call_pv("expo", G_SCALAR); SPAGAIN; printf ("%d\n", POPi); PUTBACK; FREETMPS; LEAVE; } int main (int argc, char **argv, char **env) { char *my_argv[] = { "", "power.pl" }; my_perl = perl_alloc(); perl_construct( my_perl ); perl_parse(my_perl, xs_init, 2, my_argv, (char **)NULL); perl_run(my_perl); PerlPower(3, 4); perl_destruct(my_perl); perl_free(my_perl); }

PERL FILE
use DBI; sub expo { my ($a, $b) = @_; return $a ** $b; }

You could ask what is the use of "use DBI" ? The reason is i am getting this error in some other files also and also out of curiosity.Could any one find the reason for the error message

Thanks
Kiran

Replies are listed 'Best First'.
Re: memory leak <<<PerlEmbed
by derby (Abbot) on Dec 21, 2005 at 14:54 UTC

    Sounds like an issue with your DBI install. I cannot replicate the error on my Gentoo box running perl 5.8.7 and DBI 1.48. (nor on my redhat box running perl 5.8.2 and DBI 1.43)

    -derby
      Yes,what you said is right.I tried it on a machine with perl5.8.5 and it is working correctly

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://518299]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found