Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

memory leak <<<PerlEmbed

by jithoosin (Scribe)
on Dec 21, 2005 at 13:24 UTC ( #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[] = { "", "" }; 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); }

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


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)

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2023-01-27 13:54 GMT
Find Nodes?
    Voting Booth?

    No recent polls found