I do not think there is anything wrong here. The returned buffer belongs
to text element. If the user wants to use it, her or she must make a
deep copy of what is returned.
So the correct code is:
outer()
{
axis2_char_t *text = strdup(axiom_element_get_text(e_text, env,
n_text)); // or AXIS2_STRDUP
inner(env, n_text, e_text);
printf(text);
}
We do not need to keep an array, if the above discipline is applied. Of
course this should be documented.
Samisa...
Supun Kamburugamuva wrote:
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.
------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG.
Version: 8.0.100 / Virus Database: 270.3.0/1505 - Release Date: 6/16/2008 7:20 AM
--
Samisa Abeysinghe
Director, Engineering; WSO2 Inc.
http://www.wso2.com/ - "The Open Source SOA Company"
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]