If a node set is computed more than once for an XPath expression, a memory leak occurs because the "operator=" overloaded function in node_set.cpp does not check for a previous allocation of the "vpp_node_set" and "op_attrib" members of the object and free them appropriately.
I managed to reproduce this consistently via the following test:
1.) Load a document
2.) Compute a node set via the "u_compute_xpath_node_set()" function repeatedly, such as in the condition of a for loop
Example code:
[code]
TiXmlDocument* document = new TiXmlDocument( "test.xml" );
document->LoadFile();
TinyXPath::xpath_processor proc( document->RootElement(), "/Test/*/text()" );
for ( unsigned int i = 0; i < proc.u_compute_xpath_node_set(); i++ )
{
TiXmlNode* node = proc.XNp_get_xpath_node( i );
printf( "%s\n", node->value() );
}
[code]
I have attached a patch that solves this memory leak.
Memory leak fix