Menu

#4 Memory Leak in TinyXPath

open
nobody
None
6
2012-06-04
2012-06-04
No

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.

Related

Code: code

Discussion

  • Benjamin Rood

    Benjamin Rood - 2012-06-04

    Memory leak fix

     
  • Benjamin Rood

    Benjamin Rood - 2012-06-04
    • priority: 5 --> 6
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.