[mp2]Perl_parse free some resources

[mp2]Perl_parse free some resources

am 05.06.2008 21:55:39 von Dinesh Premalal

------=_Part_9441_21395361.1212695739632
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi All,

I'm using modperl2 with PerlRun to invoke my cgi script. My server
configuration is as follows

Apache/2.2.6 (Unix) Axis2C/1.3.1 mod_perl/2.0.4 Perl/v5.10.0

script I invoke via mod_perl2 (say echo_service.pl) call to some other C
program. In that c program going to invoke a perl function. However when I
call perl function from C ,perl_parse method seems freeing some resources
that mod_perl2 using.

Here is the valgrind trace.
-----------------------------------------
==21847== Invalid read of size 4
==21847== at 0x4A0A7C8: Perl_save_clearsv (scope.c:490)
==21847== by 0x4975B53: Perl_pp_padsv (pp_hot.c:309)
==21847== by 0x492DB39: Perl_runops_debug (dump.c:1931)
==21847== by 0x4969A2B: Perl_call_sv (perl.c:2646)
==21847== by 0x481A593: modperl_callback (modperl_callback.c:101)
==21847== by 0x481B8C4: modperl_callback_run_handlers
(modperl_callback.c:262)
==21847== by 0x481C458: modperl_callback_per_dir (modperl_callback.c:369)
==21847== by 0x4814668: modperl_response_handler_run (mod_perl.c:1000)
==21847== by 0x4814940: modperl_response_handler_cgi (mod_perl.c:1100)
==21847== by 0x807D864: ap_run_handler (in /usr/local/apache2/bin/httpd)
==21847== by 0x807DFB4: ap_invoke_handler (in
/usr/local/apache2/bin/httpd)
==21847== by 0x809BC1F: ap_process_request (in
/usr/local/apache2/bin/httpd)
==21847== Address 0x51cf5cc is 8 bytes after a block of size 28 free'd
==21847== at 0x402265C: free (vg_replace_malloc.c:323)
==21847== by 0x48CCD1D: S_op_destroy (op.c:417)
==21847== by 0x48D2EBC: Perl_append_list (op.c:2588)
==21847== by 0x48C98BC: Perl_yyparse (perly.y:189)
==21847== by 0x4967A5D: S_parse_body (perl.c:2230)
==21847== by 0x4965FD3: perl_parse (perl.c:1650)
==21847== by 0x4CFDA29: wsf_xml_msg_recv_invoke_other
(wsf_xml_msg_recv.c:429)
==21847== by 0x4CFD329: wsf_xml_msg_recv_invoke_business_logic_sync
(wsf_xml_msg_recv.c:207)
==21847== by 0x46F899E: axis2_msg_recv_invoke_business_logic
(msg_recv.c:392)
==21847== by 0x46F877C: axis2_msg_recv_receive_impl (msg_recv.c:319)
==21847== by 0x46F89FA: axis2_msg_recv_receive (msg_recv.c:431)
==21847== by 0x46E9F34: axis2_engine_receive (engine.c:315)


Any idea on fixing this segmentation fault would be a great help.

thanks,
Dinesh

--
http://nethu.org/

------=_Part_9441_21395361.1212695739632
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi All,

        I'm using modperl2 with PerlRun to invoke my cgi script. My server configuration is as follows

Apache/2.2.6 (Unix) Axis2C/1.3.1 mod_perl/2.0.4 Perl/v5.10.0

script I invoke via mod_perl2 (say echo_service.pl) call to some other C program. In that c program going to invoke a perl function. However when I call perl function from C ,perl_parse method seems freeing some resources that mod_perl2 using. 


Here is the valgrind trace.
-----------------------------------------
==21847== Invalid read of size 4
==21847==    at 0x4A0A7C8: Perl_save_clearsv (scope.c:490)
==21847==    by 0x4975B53: Perl_pp_padsv (pp_hot.c:309)

==21847==    by 0x492DB39: Perl_runops_debug (dump.c:1931)
==21847==    by 0x4969A2B: Perl_call_sv (perl.c:2646)
==21847==    by 0x481A593: modperl_callback (modperl_callback.c:101)
==21847==    by 0x481B8C4: modperl_callback_run_handlers (modperl_callback.c:262)

==21847==    by 0x481C458: modperl_callback_per_dir (modperl_callback.c:369)
==21847==    by 0x4814668: modperl_response_handler_run (mod_perl.c:1000)
==21847==    by 0x4814940: modperl_response_handler_cgi (mod_perl.c:1100)

==21847==    by 0x807D864: ap_run_handler (in /usr/local/apache2/bin/httpd)
==21847==    by 0x807DFB4: ap_invoke_handler (in /usr/local/apache2/bin/httpd)
==21847==    by 0x809BC1F: ap_process_request (in /usr/local/apache2/bin/httpd)

==21847==  Address 0x51cf5cc is 8 bytes after a block of size 28 free'd
==21847==    at 0x402265C: free (vg_replace_malloc.c:323)
==21847==    by 0x48CCD1D: S_op_destroy (op.c:417)
==21847==    by 0x48D2EBC: Perl_append_list (op.c:2588)

==21847==    by 0x48C98BC: Perl_yyparse (perly.y:189)
==21847==    by 0x4967A5D: S_parse_body (perl.c:2230)
==21847==    by 0x4965FD3: perl_parse (perl.c:1650)
==21847==    by 0x4CFDA29: wsf_xml_msg_recv_invoke_other (wsf_xml_msg_recv.c:429)

==21847==    by 0x4CFD329: wsf_xml_msg_recv_invoke_business_logic_sync (wsf_xml_msg_recv.c:207)
==21847==    by 0x46F899E: axis2_msg_recv_invoke_business_logic (msg_recv.c:392)
==21847==    by 0x46F877C: axis2_msg_recv_receive_impl (msg_recv.c:319)

==21847==    by 0x46F89FA: axis2_msg_recv_receive (msg_recv.c:431)
==21847==    by 0x46E9F34: axis2_engine_receive (engine.c:315)


Any idea on fixing this segmentation fault would be a great help.

thanks,

Dinesh

--


------=_Part_9441_21395361.1212695739632--

Re: [mp2]Perl_parse free some resources

am 05.06.2008 22:41:40 von Dinesh Premalal

------=_Part_9567_17183702.1212698500502
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

and my functions are.

static axiom_node_t *
wsf_xml_msg_recv_invoke_other (axis2_msg_recv_t* msg_recv,
const axutil_env_t* env,
wsf_svc_info_t* svc_info,
axis2_msg_ctx_t* in_msg_ctx,
axis2_msg_ctx_t* out_msg_ctx,
axis2_char_t* function_name,
axis2_char_t* class_name)
{
AXIS2_PARAM_CHECK (env->error, svc_info, NULL);
AXIS2_PARAM_CHECK (env->error, in_msg_ctx, NULL);
AXIS2_PARAM_CHECK (env->error, out_msg_ctx, NULL);

axiom_node_t *node = NULL;
axiom_node_t *om_node = NULL;
axiom_soap_envelope_t *envelope = NULL;
axiom_soap_body_t *body = NULL;
axis2_char_t *retstr = NULL;

/* extracting payload from the soap message */
envelope = axis2_msg_ctx_get_soap_envelope (in_msg_ctx, env);
body = axiom_soap_envelope_get_body (envelope, env);
om_node = axiom_soap_body_get_base_node (body, env);
om_node = axiom_node_get_first_child (om_node, env);

axis2_char_t *embedding[] = {"", NULL};
if (!svc_info->script_filename)
{
AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI,
"perl function invocation failed, script_file name
not found for \
service %s", svc_info->svc_name);
return NULL;
}
/* passing script real path into perl interpreter. */
embedding[1] = svc_info->script_filename;

my_perl = perl_alloc();
perl_construct( my_perl );
/* loading WSO2::WSF::C and WSO2::WSF::Server using dynamic loader */
eval_pv("use WSO2::WSF::C", FALSE);
eval_pv("use WSO2::WSF::Server", FALSE);

if (perl_parse(my_perl, xs_init, 2, embedding, NULL))
{
AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "perl_parse method
failed");
return NULL;
}

perl_run(my_perl);

if (SvTRUE(ERRSV))
{
AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "invoke perl function
failed");
}

retstr = invoke_perl_function(env, om_node, function_name, NULL);

if (retstr)
{
node = wsf_util_deserialize_buffer (env, retstr);
}

perl_destruct(my_perl);
perl_free(my_perl);
return node;
}

static axis2_char_t *
invoke_perl_function(const axutil_env_t *env, axiom_node_t *om_node,
axis2_char_t *operation, axis2_char_t *class_name)
{
int count = 0;
axis2_char_t *inmsg = NULL;
axis2_char_t *ret = NULL;

if (!operation)
{
AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI,
"invoking perl function failed, operation not
available");
return;
}

if (om_node)
{
inmsg = axiom_node_to_string (om_node, env);
}

dSP ;

ENTER ;
SAVETMPS ;

PUSHMARK(SP) ;
XPUSHs(sv_2mortal(newSVpv(inmsg, 0)));
PUTBACK;

/* calling user perl function which returns a scaler value */
count = perl_call_pv(operation, G_SCALAR);
SPAGAIN;

if (count != 1)
{
croak("perl function invocation failed") ;
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
"perl function %s invocation failed", operation);

}

/* we pop string from the stack and doing strdup on it */
ret = savepv(POPpx);

PUTBACK;
FREETMPS ;
LEAVE ;
return ret;
}


/* xs_init is for support dynamic loading of modules */
static void
xs_init(pTHX)
{
char *file = __FILE__;
dXSUB_SYS;

/* DynaLoader is a special case */
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}

thanks,
Dinesh
--
http://nethu.org/

------=_Part_9567_17183702.1212698500502
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

and my functions are.

static axiom_node_t *
wsf_xml_msg_recv_invoke_other (axis2_msg_recv_t* msg_recv,
                               const axutil_env_t* env,

                               wsf_svc_info_t* svc_info,
                               axis2_msg_ctx_t* in_msg_ctx,
                               axis2_msg_ctx_t* out_msg_ctx,
                           &
nbsp;   axis2_char_t* function_name,


                               axis2_char_t* class_name)
{
    AXIS2_PARAM_CHECK (env->error, svc_info, NULL);
    AXIS2_PARAM_CHECK (env->error, in_msg_ctx, NULL);
    AXIS2_PARAM_CHECK (env->error, out_msg_ctx, NULL);



    axiom_node_t *node = NULL;
    axiom_node_t *om_node = NULL;
    axiom_soap_envelope_t *envelope = NULL;
    axiom_soap_body_t *body = NULL;
    axis2_char_t *retstr = NULL;

    /* extracting payload from the soap message */


    envelope = axis2_msg_ctx_get_soap_envelope (in_msg_ctx, env);
    body = axiom_soap_envelope_get_body (envelope, env);
    om_node = axiom_soap_body_get_base_node (body, env);
    om_node = axiom_node_get_first_child (om_node, env);



    axis2_char_t *embedding[] = {"", NULL};
    if (!svc_info->script_filename)
    {
        AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI,
                         "perl function invocation failed, script_file name not found for \


service %s", svc_info->svc_name);
        return NULL;
    }
    /* passing script real path into perl interpreter. */
    embedding[1] = svc_info->script_filename;

    my_perl = perl_alloc();


    perl_construct( my_perl );
    /* loading WSO2::WSF::C and WSO2::WSF::Server using dynamic loader */
    eval_pv("use WSO2::WSF::C", FALSE);
    eval_pv("use WSO2::WSF::Server", FALSE);



    if (perl_parse(my_perl, xs_init, 2, embedding, NULL))
    {
        AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "perl_parse method failed");
        return NULL;
    }

    perl_run(my_perl);



    if (SvTRUE(ERRSV))
    {
        AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "invoke perl function failed");
    }

    retstr = invoke_perl_function(env, om_node, function_name, NULL);



    if (retstr)
    {
        node = wsf_util_deserialize_buffer (env, retstr);
    }

    perl_destruct(my_perl);
    perl_free(my_perl);
    return node;
}

static axis2_char_t *
invoke_perl_function(const axutil_env_t *env, axiom_node_t *om_node,


                     axis2_char_t *operation, axis2_char_t *class_name)
{
    int count = 0;
    axis2_char_t *inmsg = NULL;
    axis2_char_t *ret = NULL;

    if (!operation)
    {
        AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI,


                         "invoking perl function failed, operation not available");
        return;
    }

    if (om_node)
    {
        inmsg = axiom_node_to_string (om_node, env);
    }



    dSP ;

    ENTER ;
    SAVETMPS ;

    PUSHMARK(SP) ;
    XPUSHs(sv_2mortal(newSVpv

(inmsg, 0)));
    PUTBACK;

    /* calling user perl function which returns a scaler value */

    count = perl_call_pv(operation, G_SCALAR);

    SPAGAIN;

    if (count != 1)
    {
        croak("perl function invocation failed") ;
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                        "perl function %s invocation failed", operation);



    }

    /* we pop string from the stack and doing strdup on it */
    ret = savepv(POPpx);

    PUTBACK;
    FREETMPS ;
    LEAVE ;
    return ret;
}


/* xs_init is for support dynamic loading of modules */


static void
xs_init(pTHX)
{
    char *file = __FILE__;
    dXSUB_SYS;

    /* DynaLoader is a special case */
    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}


thanks,
Dinesh
--


------=_Part_9567_17183702.1212698500502--