Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Memory leak in er_compute_xpath

Help
John Cruz
2009-06-09
2013-04-30
  • John Cruz
    John Cruz
    2009-06-09

    I haven't gone deeper in my debugging but I can definitely say that there is a memory leak being created when calling TinyXPath::xpath_processor::er_compute_xpath() from within S_compute_xpath().

    I'm not sure if I am just invoking it wrong but here is an overview of how I use TinyXPath...

    // CODE: START
    std::string xmlstr;
    // xmlstr = some valid XML string

    std::string xpathstr;
    // xpathstr = some valid xpath string

    TiXmlDocument doc;
    doc.Parse( xmlstr.str());

    if( doc.Error()) return "";

    TinyXPath::xpath_processor x( doc.RootElement(), xpathstr );
    std::string ret=x.S_compute_xpath().c_str();

    return ret;
    // CODE: END

    Is there any free/delete function I should be calling?

    Thanks in advance!

    John

     
    • John Cruz
      John Cruz
      2009-06-09

      BTW,

      TinyXPath::xpath_processor x( doc.RootElement(), xpathstr );

      should read as

      TinyXPath::xpath_processor x( doc.RootElement(), xpathstr.c_str());

       
  • Benjamin Rood
    Benjamin Rood
    2012-09-13

    Since you constructed the object on the stack, it will be deleted when the function returns.  Hopefully, there are no undiscovered memory leaks in TinyXPath because the destructor didn't clean up after itself properly.