Hi all,

Recently I went through this method and for me there are several issues with
this method. Here is a scenario where this method will fail

Assume we have a Axiom element with some text in it. Lets say; node is
n_text and element is e_text. We have two functions called outer and inner.
inner is called by the outer funtion.

outer()
{
    axis2_char_t *text = axiom_element_get_text(e_text, env, n_text);
    inner(env, n_text, e_text);
    printf(text);
}

inner(axutil_env_t *env, axiom_node_t *node, axiom_element_t *element)
{
    axis2_char_t *text = axiom_element_get_text(element. env, node);
    printf(text);
}

Innner method will be successful but the outer method will seg-fault.
axiom_element_get_text method allocates a new buffer for the text, copy the
string to the new buffer, keeps a pointer to this buffer in axiom_element_t
and returns it. But axiom_element_t has room for keeping track of only one
such buffer. When the method is called for the second time it free the first
buffer, allocates a new buffer and keep track of the newly allocated buffer.
The way this method is designed we should have to keep track of an array of
buffers inside the axiom_element_t structure and free all the buffers at the
end.

We are going in to all these trouble because of the mixed content. In this
method all the text in mixed content will be concatenated and returned. I
think this is not a good approach for C. In case of mixed content we should
have return an array or strings. Then the user has more control over weather
to concatenate them or not and we won't have the problems that I have
mentioned earlier.

I will document this issue in the axiom_element_get_text method.

Supun.

Reply via email to