I only changed one line in the Axis2 code base.  In msg_ctx.c, there is a
commented out AXIOM_SOAP_ENVELOPE_FREE.  I simply uncommented it.

The other change I did, was in the generated code for my WSDL types:
specifically in build_om

axis2_MyType_build_om (...) {
   text_value = AXIOM_ELEMENT_GET_TEXT(current_element, env, current_node
);
   text_value = AXIS2_STRDUP(text_value, env);
   AXIS2_MYTYPE_SET_MYTEXT(MyType, env,
                                                         text_value);
}


I added the AXIS2_STRDUP.  Code should be added to do this in the WSDL2C
code generator.  I'm not familiar with this aspect of the code, so I'm
explaining it here so whoever is can hopefully implement it.  My types were
generated with an old nightly build (in November, I believe), and have since
been heavily modified by hand.

The big issue here is getting the code generator to do the correct thing.
Because, as it currently stands, fixing the memory leak will cause a crash
due to double free, if the generated type code is bad.  There needs to be
some coordination there, and I don't know who handles these things.

I'll be glad to provide any help with this, just let me know what you need.

Jared


On 2/27/07, Nandika Jayawardana <[EMAIL PROTECTED]> wrote:

Hi Jared,

Can you attach you fixes to the jira-537...

Thanks
Nandika


On 2/27/07, Jared Hanson <[EMAIL PROTECTED]> wrote:
>
> An update:
>
> I implemented my suggestion within my own types.  Any text values they
> read from axiom_element, they copy before setting them in their own
> structures.  I also uncommented the AXIOM_SOAP_ENVELOPE_FREE() in msg_ctx.
>
> The result was a dramatic reduction in memory leaks.  It's dependent on
> how complex your SOAP messages are, but in my particular case, they dropped
> to about 1% of what they were previously.
>
> Also note, I'm running with the patch I sent previously, which fixes the
> socket handle leak along with other small amounts of memory.
>
> Jared
>
>
> On 2/26/07, Jared Hanson <[EMAIL PROTECTED] > wrote:
> >
> > One other thought on this:
> >
> > Exposing an AXIOM_ELEMENT_GET_TEXT_ASSUME_OWNERSHIP, or some
> > equivalent would also work.  This would give an option for avoiding an
> > unnecessary memcpy.
> >
> > Jared
> >
> > On 2/26/07, Jared Hanson <[EMAIL PROTECTED] > wrote:
> > >
> > > I've been digging into this one, and am writing in to report my
> > > progress.  To refresh, this is in reference to the major memory leak 
caused
> > > by having AXIOM_SOAP_ENVELOPE_FREE(msg_ctx->soap_envelope, env); commented
> > > out in msg_ctx.c
> > >
> > > When putting that line in, the code flows into
> > > axiom_soap_builder_free(), axiom_stax_builder_free(), and
> > > axiom_document_free().  Somewhere in axiom_document_free(), the 
application
> > > will crash.  This appears to be caused by a double free, in which memory 
is
> > > owned by an om_element->text_value and the "application-level" types used 
in
> > > the SOAP message.
> > >
> > > For example: here is a pseudo generated type:
> > >
> > > axis2_MyType_free (...) {
> > >     if (MyType_impl->attrib_MyText != NULL)
> > >     {
> > >         AXIS2_FREE( env-> allocator, MyType_impl->attrib_MyText);
> > >         MyType_impl->attrib_MyText = NULL;
> > >     }
> > > }
> > >
> > > axis2_MyType_build_om (...) {
> > >     text_value = AXIOM_ELEMENT_GET_TEXT(current_element, env,
> > > current_node );
> > >     AXIS2_MYTYPE_SET_MYTEXT(MyType, env,
> > >
> > > text_value);
> > > }
> > >
> > > axis2_MyType_set_MyText(param_MyText) {
> > >     MyType_impl->attrib_MyText = param_MyText;
> > > }
> > >
> > >
> > > In this case, MyType has assumed ownership of the text returned by
> > > axiom_element_get_text().  It will free it in its free function.  However,
> > > if you look at axiom_element_get_text(), the following occurs:
> > >
> > > axiom_element_get_text(...) {
> > > ...
> > > dest = AXIS2_STRDUP(temp_text, env);
> > > ...
> > > om_element->text_value = dest;
> > > return om_element->text_value;
> > > }
> > >
> > > Then, in axiom_element_free():
> > >
> > > axiom_element_free() {
> > >     if (om_element->text_value)
> > >     {
> > >         AXIS2_FREE(env->allocator, om_element->text_value);
> > >         om_element->text_value = NULL;
> > >     }
> > > }
> > >
> > >
> > > The result of which, is that two objects lay claim to memory, and
> > > both try to free it.  This obviously will cause a crash, and is, I'm
> > > guessing, why the AXIOM_SOAP_ENVELOPE_FREE() was commented out in the 
first
> > > place.
> > >
> > > I think what needs to be happening is that the WSDL->code generator
> > > needs to be duplicating the text_values it reads before setting them.
> > > Before 1.0, this needs to be ironed out, so there is no discrepancy,
> > > because the memory leak is very severe.
> > >
> > > I'm posting the information so others can look into it as well.  I'd
> > > appreciate knowing what other people discover, so that these items can be
> > > addressed.
> > >
> > > Thanks,
> > > Jared
> > >
> > >
> > >
> > >
> >
>


--
[EMAIL PROTECTED]
WSO2 INC www.wso2.com

Reply via email to