xml parsing memory leak

Discussion in 'XML' started by keepyourstupidspam, Nov 23, 2005.

  1. In the code below I am trying to read text in an xml file, this works
    fine but creates a memory leak of about 400K each time. This code is
    called from a loop in a windows service so I can not just terminate the
    app to cleanup, any ideas how to free this memory.


    ////////////////////////

    xercesc_2_4::XercesDOMParser* parser = new
    xercesc_2_4::XercesDOMParser();


    parser->setValidationScheme(xercesc_2_4::XercesDOMParser::Val_Never);
    parser->setDoNamespaces(false);

    xercesc_2_4::ErrorHandler* errHandler = (xercesc_2_4::ErrorHandler*)
    new xercesc_2_4::HandlerBase();

    parser->setErrorHandler(errHandler);

    string metaDataFile = GetMetadataFileName(submissionID);

    try
    {
    parser->parse(metaDataFile.c_str());
    }

    catch (const xercesc_2_4::XMLException& toCatch)
    {
    char* message =
    xercesc_2_4::XMLString::transcode(toCatch.getMessage());
    std::cout << "Exception message is: \n" << message << "\n";
    xercesc_2_4::XMLString::release(&message);
    delete parser;
    delete errHandler;
    }

    catch (const xercesc_2_4::DOMException& toCatch)
    {
    char* message = xercesc_2_4::XMLString::transcode(toCatch.msg);
    std::cout << "Exception message is: \n" << message << "\n";
    xercesc_2_4::XMLString::release(&message);
    delete parser;
    delete errHandler;
    }

    catch (...)
    {
    std::cout << "Unexpected Exception \n";
    delete parser;
    delete errHandler;
    }

    xercesc_2_4::DOMDocument* xmlDoc = parser->getDocument();

    if( NULL == xmlDoc )
    {
    std::cout<<"xml doc is null, quit\n";
    delete parser;
    delete errHandler;
    }


    xercesc::DOMNodeList* list;
    xercesc::DOMNode* node;
    const XMLCh* n;
    char* xmlval = "";
    string szXmlVal = "";

    list = xmlDoc->getElementsByTagName(
    XMLString::transcode("SubmissionDate") );
    node = list->item(0);
    if( xercesc::DOMNode::ELEMENT_NODE == node->getNodeType() )
    {
    n = node->getFirstChild()->getNodeValue();
    xmlval = xercesc_2_4::XMLString::transcode(n);
    szXmlVal = xmlval;
    xercesc_2_4::XMLString::release(&xmlval);
    }


    delete parser;
    delete errHandler;
    return szXmlVal;


    /////////

    Enda Mannion
    keepyourstupidspam, Nov 23, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. s.subbarayan

    Dynamic memory allocation and memory leak...

    s.subbarayan, Mar 18, 2005, in forum: C Programming
    Replies:
    10
    Views:
    701
    Eric Sosman
    Mar 22, 2005
  2. Richard Heathfield

    Leak or no leak ??

    Richard Heathfield, Jul 10, 2006, in forum: C Programming
    Replies:
    4
    Views:
    352
    Richard Heathfield
    Jul 10, 2006
  3. cham
    Replies:
    5
    Views:
    770
  4. Mark Probert
    Replies:
    4
    Views:
    328
    Mark Probert
    Feb 9, 2005
  5. Erik Wasser
    Replies:
    5
    Views:
    452
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page