neither the parser nor the membuf need to be heap-allocated.
this kind of coding style leaks memory in case of exceptions.
perhaps the process is leaking memory only on bad input.

regards
tobias

----- Original Message ----- From: "Abhinav Kishore Srivastava" <[email protected]>
To: <[email protected]>
Sent: Monday, June 15, 2009 12:55 PM
Subject: Regd issue : Memory leak in 'Parse' function of DOMParser


Hi,

There is a memory leak in the parse function of XercesDOMParser. Please find below the details:

OS used: Solaris 10
Xerces version: 2.8.0
Software used: Rogue wave libraries for string functions.

Code Snippet which leaks:

RWCString xmlString;
XmlProcessData  m_xmlDocData;
ParserErrorHandler*      m_errorHandler;

               int errorCount = 0;

               m_domParser = new XercesDOMParser();
RWCString schemaLocationsString;
                               bool noNameSpace;
m_xmlDocData.GetSchemaLocation(schemaLocationsString, noNameSpace)
                               
m_domParser->setExternalSchemaLocation(schemaLocationsString);
                               
m_domParser->setValidationSchemaFullChecking(false);

                               XercesDOMParser::ValSchemes valScheme;
if (m_xmlDocData.GetXsdValidationLevel() == XmlProcessData::VALIDATION_OFF) valScheme = XercesDOMParser::Val_Never; else if (m_xmlDocData.GetXsdValidationLevel() == XmlProcessData::VALIDATION_ON) valScheme = XercesDOMParser::Val_Always;
                               else
valScheme = XercesDOMParser::Val_Auto;

                               m_domParser->setValidationScheme(valScheme);
m_domParser->setDoNamespaces(true); // optional
                               m_domParser->setDoSchema(true);
                               m_domParser->setErrorHandler(m_errorHandler);
               }
               RWCString theString = xmlbuffer;

               m_errorHandler->resetErrors();

               MemBufInputSource* membuf;

                               membuf = new MemBufInputSource(
(const XMLByte*)theString.data(), strlen(theString.data()), "APIXMLInterface",false);


const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();


m_domParser->parse(*membuf); //memory utilization increases here and later on when delete m_domParser is called, it is not released.


const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); unsigned long duration = endMillis - startMillis;
                               m_doc = m_domParser->getDocument();
                               delete membuf;
                               membuf = 0;
                               delete m_domParser;
                               m_domParser = 0;

Can anyone suggest why is the memory leak happening and what can be done to prevent this.
Thanks and Regards,
Abhinav Kishore
GTCS- ASG
Desk:+91 20 22970170
Mob:0-9689942815
Team phone (UK): 01977590500


**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail
address. Messages sent to or from this e-mail address may be stored on the
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to