I'm trying to call a Perl function from C code and clean the
interpreter I just created. I have a Perl script hosted with Apache +
mod_perl and when a request comes to the file (say example.pl) it'll
call a C function which is wrapped with SWIG. I'm getting the global
request via Apache2::RequestUtil->request() and fills a C struct with
the all the request parameters and pass it to a C function.

In this function, after figuring out what function to call by looking
at request data, that function is called using call_pv(). Note that
this function is also defined in the same file (example.pl). At the
time of the call_pv() since it cannot get the global request I have
put the part that gets the global request inside if defined
$ENV{MOD_PERL} block.

The issue I'm facing is, after,


gets called, seems that it's not only affecting the Perl interpreter
instance I just created but some global state as well. From valgrind
I can see that it tries to access the freed pointer. So I tried to
change the variable name my_perl to something else but macros like dSP
seems to be using that.

When I clean up the interpreter within my function, does it affect
mod_perl? Is there a way I can get access to the interpreter used by
mod_perl so that I can execute a Perl function after using that as an
argument to perl_parse()?

Thanks in advance,