You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Alberto Massari <am...@datadirect.com> on 2006/10/09 10:05:55 UTC

RE: XercesDOMParser::parse(const InputSource& source) method leaks

Hi Pranav,
I see at least three leaks in your code:
1) m_pDOMParser is allocated but not deleted; being part of the class 
it's possible that your destructor will delete it, but in any case 
you will leak it if you call CreateDOMTree more than once (add a 
"delete m_pDOMParser" before creating a new one)
2) if the XML being parsed has an error, the memBufIS and pStr 
variables will not be deleted; you should either add a try/catch 
block around the parse() call or use a Janitor object to perform the 
cleanup automatically when leaving scope.

Hope this helps,
Alberto

At 11.26 09/10/2006 +0530, Pranav, Savkur wrote:


>Hello,
>         We're using the 2.2 version of the xerces C++ dll i.e 
> xerces-c_2_2_0.dll.
>We use the
>"parse(const InputSource& source);" method of XercesDOMParser as below:
>
>void CSPVXMLParserWrapper::CreateDOMTree(CStringArray& 
>p_cstrArrayErrorsDescription)
>{
>                 m_pDOMParser = new XERCES_CPP_NAMESPACE::XercesDOMParser;
>                 m_pDOMParser->resetDocumentPool();
>
> 
>m_pDOMParser->setExternalNoNamespaceSchemaLocation(strSchemaFile);
>                                 //Get all errors
> 
>m_pDOMParser->setExitOnFirstFatalError(true);
>                                 //All validation errors are fatal.
> 
>m_pDOMParser->setValidationConstraintFatal(true);
>                                 //Set the validation scheme
> 
>m_pDOMParser->setValidationScheme(XERCES_CPP_NAMESPACE::XercesDOMParser::Val_Auto 
>);
>                                 //Set schema validation
> 
>m_pDOMParser->setValidationSchemaFullChecking(false);
>                                 //Use namespaces and schema
>                                 m_pDOMParser->setDoNamespaces(true);
>                                 m_pDOMParser->setDoSchema(true);
>                                 //MOD001V5.2:to correct  DF1487 change start
> 
>m_pDOMParser->setIncludeIgnorableWhitespace(false);
>
>                         const XMLCh* const bufID = NULL;
>                         char* pStr = StringToChar(m_XMLFileContents);
>
>                         MemBufInputSource* memBufIS = new MemBufInputSource(
>                                  (const unsigned char *const)  pStr
>                                 ,strlen(pStr)
>                                 , bufID
>                                 , false
>                                 );
>                         TRACE_INFO("Entering 
> CSPVXMLParserWrapper::CreateDOMTree() formed 
> MemBufInputSourceObject Successfully");
>
>                         m_pDOMParser->parse(*memBufIS);
>                         TRACE_INFO("Entering 
> CSPVXMLParserWrapper::CreateDOMTree() Done parsing");
>
>                         delete memBufIS;
>
>                         memBufIS = NULL;
>
>                         delete [] pStr;
>
>                         m_ppDOMDocument = m_pDOMParser->getDocument();
>
>                         if(NULL != m_ppDOMDocument)
>                         {
>                         TRACE_INFO("Entering 
> CSPVXMLParserWrapper::CreateDOMTree() got m_ppDOMDocument");
>                         //populate rootnode pointer
>                         m_ppRootDOMNode = 
> m_ppDOMDocument->getDocumentElement();
>                         if(m_ppRootDOMNode)
>                         {
>                                 TRACE_INFO("Entering 
> CSPVXMLParserWrapper::CreateDOMTree() got m_ppRootDOMNode");
>
>                         }
>                         else
>                         {
>                                 TRACE_INFO("Entering 
> CSPVXMLParserWrapper::CreateDOMTree() NULL m_ppRootDOMNode");
>
>                                 sifRetCode = ERR_FAILURE;
>                                 m_strErrorString = _T("Exception 
> During Parsing the input XML File.Please check if the XML input 
> conforms to the schema");
>
>                         }
>                         }
>                         else
>                         {
>                         TRACE_INFO("Entering 
> CSPVXMLParserWrapper::CreateDOMTree() NULL m_ppDOMDocument");
>                         sifRetCode = ERR_FAILURE;
>                         m_strErrorString = _T("Exception During 
> Parsing the input XML File.Please check if the XML input conforms 
> to the schema");
>
>                         }
>
>}
>
>When we run a memory validation tool on this code, memory leaks are reported
>
>Can you pls let me know if what we're doing in this piece of code is 
>not correct. And how it must be done.
>We want to parse an XML String and generate the DOMdocument and root 
>pointers for referencing the DOM.
>
>Pls reply soon.
>
>Thanks and best regards,
>Pranav
>
>The new company Nokia Siemens Networks is expected to start 
>operations by January 1, 2007, subject to customary regulatory 
>approvals, the completion of standard closing conditions, and the 
>agreement of a number of detailed implementation steps.
>
>Disclaimer:
>This e-mail may contain trade secrets or privileged, undisclosed or 
>otherwise confidential information. If you have received this e-mail 
>in error, you are hereby notified that any review, copying or 
>distribution of it is strictly prohibited. Please inform us 
>immediately and destroy the original transmittal. Thank you for your 
>cooperation.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


RE: XercesDOMParser::parse(const InputSource& source) method leaks

Posted by Alberto Massari <am...@datadirect.com>.
Hi Pranav,

At 14.42 09/10/2006 +0530, Pranav, Savkur wrote:
>Hello Alberto,
>         thank you for the quick reply.
>Actually I am deleting the m_pDomParser in the destructor of my class as
>below:
>
>         if(NULL != m_pDOMParser)
>         {
>                 TRACE_INFO("Entering
>CSPVXMLParserWrapper::ReleaseXMLTree() DOMParser");
>                 delete m_pDOMParser;
>                 m_pDOMParser = 0 ;
>         }
>
>This code is getting called too.so we may not have problems here.

It depends how many times you are calling that method; if you call it 
more than once, you will leak the previously allocated object.

>Is there a link to check how I can use the Janitor object?

It is widely used in the samples (at least, in the 2.7 version, I 
don't even remember if Janitor was available in the 2.2 version...)

>The memory validation tool points to DOMDocumentImpl::allocate. To where
>the leak is
>Also I tried using Xerces 2.7 but doing a
>"m_pDOMParser->setDoNamespaces(true);" is resulting in the
>getDocumentElement returning a false.

If this happens, you should register an error handler that will get 
the description of the error occurring.

Alberto

>This is for the same XML file that I tried parsing with Xerces 2.2 and
>the same xsd(schema)
>
>Best regards,
>Pranav
>
>
>-----Original Message-----
>From: Alberto Massari [mailto:amassari@datadirect.com]
>Sent: Monday, October 09, 2006 1:36 PM
>To: c-dev@xerces.apache.org
>Subject: RE: XercesDOMParser::parse(const InputSource& source) method
>leaks
>
>Hi Pranav,
>I see at least three leaks in your code:
>1) m_pDOMParser is allocated but not deleted; being part of the class
>it's possible that your destructor will delete it, but in any case you
>will leak it if you call CreateDOMTree more than once (add a "delete
>m_pDOMParser" before creating a new one)
>2) if the XML being parsed has an error, the memBufIS and pStr variables
>will not be deleted; you should either add a try/catch block around the
>parse() call or use a Janitor object to perform the cleanup
>automatically when leaving scope.
>
>Hope this helps,
>Alberto
>
>At 11.26 09/10/2006 +0530, Pranav, Savkur wrote:
>
>
> >Hello,
> >         We're using the 2.2 version of the xerces C++ dll i.e
> >xerces-c_2_2_0.dll.
> >We use the
> >"parse(const InputSource& source);" method of XercesDOMParser as below:
> >
> >void CSPVXMLParserWrapper::CreateDOMTree(CStringArray&
> >p_cstrArrayErrorsDescription)
> >{
> >                 m_pDOMParser = new
>XERCES_CPP_NAMESPACE::XercesDOMParser;
> >                 m_pDOMParser->resetDocumentPool();
> >
> >
> >m_pDOMParser->setExternalNoNamespaceSchemaLocation(strSchemaFile);
> >                                 //Get all errors
> >
> >m_pDOMParser->setExitOnFirstFatalError(true);
> >                                 //All validation errors are fatal.
> >
> >m_pDOMParser->setValidationConstraintFatal(true);
> >                                 //Set the validation scheme
> >
> >m_pDOMParser->setValidationScheme(XERCES_CPP_NAMESPACE::XercesDOMParser
> >::Val_Auto
> >);
> >                                 //Set schema validation
> >
> >m_pDOMParser->setValidationSchemaFullChecking(false);
> >                                 //Use namespaces and schema
> >                                 m_pDOMParser->setDoNamespaces(true);
> >                                 m_pDOMParser->setDoSchema(true);
> >                                 //MOD001V5.2:to correct  DF1487 change
>
> >start
> >
> >m_pDOMParser->setIncludeIgnorableWhitespace(false);
> >
> >                         const XMLCh* const bufID = NULL;
> >                         char* pStr = StringToChar(m_XMLFileContents);
> >
> >                         MemBufInputSource* memBufIS = new
>MemBufInputSource(
> >                                  (const unsigned char *const)  pStr
> >                                 ,strlen(pStr)
> >                                 , bufID
> >                                 , false
> >                                 );
> >                         TRACE_INFO("Entering
> > CSPVXMLParserWrapper::CreateDOMTree() formed MemBufInputSourceObject
> > Successfully");
> >
> >                         m_pDOMParser->parse(*memBufIS);
> >                         TRACE_INFO("Entering
> > CSPVXMLParserWrapper::CreateDOMTree() Done parsing");
> >
> >                         delete memBufIS;
> >
> >                         memBufIS = NULL;
> >
> >                         delete [] pStr;
> >
> >                         m_ppDOMDocument = m_pDOMParser->getDocument();
> >
> >                         if(NULL != m_ppDOMDocument)
> >                         {
> >                         TRACE_INFO("Entering
> > CSPVXMLParserWrapper::CreateDOMTree() got m_ppDOMDocument");
> >                         //populate rootnode pointer
> >                         m_ppRootDOMNode =
> > m_ppDOMDocument->getDocumentElement();
> >                         if(m_ppRootDOMNode)
> >                         {
> >                                 TRACE_INFO("Entering
> > CSPVXMLParserWrapper::CreateDOMTree() got m_ppRootDOMNode");
> >
> >                         }
> >                         else
> >                         {
> >                                 TRACE_INFO("Entering
> > CSPVXMLParserWrapper::CreateDOMTree() NULL m_ppRootDOMNode");
> >
> >                                 sifRetCode = ERR_FAILURE;
> >                                 m_strErrorString = _T("Exception
> > During Parsing the input XML File.Please check if the XML input
> > conforms to the schema");
> >
> >                         }
> >                         }
> >                         else
> >                         {
> >                         TRACE_INFO("Entering
> > CSPVXMLParserWrapper::CreateDOMTree() NULL m_ppDOMDocument");
> >                         sifRetCode = ERR_FAILURE;
> >                         m_strErrorString = _T("Exception During
> > Parsing the input XML File.Please check if the XML input conforms to
> > the schema");
> >
> >                         }
> >
> >}
> >
> >When we run a memory validation tool on this code, memory leaks are
> >reported
> >
> >Can you pls let me know if what we're doing in this piece of code is
> >not correct. And how it must be done.
> >We want to parse an XML String and generate the DOMdocument and root
> >pointers for referencing the DOM.
> >
> >Pls reply soon.
> >
> >Thanks and best regards,
> >Pranav


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


RE: XercesDOMParser::parse(const InputSource& source) method leaks

Posted by "Pranav, Savkur" <Pr...@siemens.com>.
Hello Alberto,
	thank you for the quick reply.
Actually I am deleting the m_pDomParser in the destructor of my class as
below:

	if(NULL != m_pDOMParser)
	{
		TRACE_INFO("Entering
CSPVXMLParserWrapper::ReleaseXMLTree() DOMParser");
		delete m_pDOMParser;		
		m_pDOMParser = 0 ;
	}
 
This code is getting called too.so we may not have problems here.
Is there a link to check how I can use the Janitor object?
The memory validation tool points to DOMDocumentImpl::allocate. To where
the leak is
Also I tried using Xerces 2.7 but doing a
"m_pDOMParser->setDoNamespaces(true);" is resulting in the
getDocumentElement returning a false.
This is for the same XML file that I tried parsing with Xerces 2.2 and
the same xsd(schema)

Best regards,
Pranav


-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com] 
Sent: Monday, October 09, 2006 1:36 PM
To: c-dev@xerces.apache.org
Subject: RE: XercesDOMParser::parse(const InputSource& source) method
leaks

Hi Pranav,
I see at least three leaks in your code:
1) m_pDOMParser is allocated but not deleted; being part of the class
it's possible that your destructor will delete it, but in any case you
will leak it if you call CreateDOMTree more than once (add a "delete
m_pDOMParser" before creating a new one)
2) if the XML being parsed has an error, the memBufIS and pStr variables
will not be deleted; you should either add a try/catch block around the
parse() call or use a Janitor object to perform the cleanup
automatically when leaving scope.

Hope this helps,
Alberto

At 11.26 09/10/2006 +0530, Pranav, Savkur wrote:


>Hello,
>         We're using the 2.2 version of the xerces C++ dll i.e  
>xerces-c_2_2_0.dll.
>We use the
>"parse(const InputSource& source);" method of XercesDOMParser as below:
>
>void CSPVXMLParserWrapper::CreateDOMTree(CStringArray&
>p_cstrArrayErrorsDescription)
>{
>                 m_pDOMParser = new
XERCES_CPP_NAMESPACE::XercesDOMParser;
>                 m_pDOMParser->resetDocumentPool();
>
> 
>m_pDOMParser->setExternalNoNamespaceSchemaLocation(strSchemaFile);
>                                 //Get all errors
> 
>m_pDOMParser->setExitOnFirstFatalError(true);
>                                 //All validation errors are fatal.
> 
>m_pDOMParser->setValidationConstraintFatal(true);
>                                 //Set the validation scheme
> 
>m_pDOMParser->setValidationScheme(XERCES_CPP_NAMESPACE::XercesDOMParser
>::Val_Auto
>);
>                                 //Set schema validation
> 
>m_pDOMParser->setValidationSchemaFullChecking(false);
>                                 //Use namespaces and schema
>                                 m_pDOMParser->setDoNamespaces(true);
>                                 m_pDOMParser->setDoSchema(true);
>                                 //MOD001V5.2:to correct  DF1487 change

>start
> 
>m_pDOMParser->setIncludeIgnorableWhitespace(false);
>
>                         const XMLCh* const bufID = NULL;
>                         char* pStr = StringToChar(m_XMLFileContents);
>
>                         MemBufInputSource* memBufIS = new
MemBufInputSource(
>                                  (const unsigned char *const)  pStr
>                                 ,strlen(pStr)
>                                 , bufID
>                                 , false
>                                 );
>                         TRACE_INFO("Entering
> CSPVXMLParserWrapper::CreateDOMTree() formed MemBufInputSourceObject 
> Successfully");
>
>                         m_pDOMParser->parse(*memBufIS);
>                         TRACE_INFO("Entering
> CSPVXMLParserWrapper::CreateDOMTree() Done parsing");
>
>                         delete memBufIS;
>
>                         memBufIS = NULL;
>
>                         delete [] pStr;
>
>                         m_ppDOMDocument = m_pDOMParser->getDocument();
>
>                         if(NULL != m_ppDOMDocument)
>                         {
>                         TRACE_INFO("Entering
> CSPVXMLParserWrapper::CreateDOMTree() got m_ppDOMDocument");
>                         //populate rootnode pointer
>                         m_ppRootDOMNode = 
> m_ppDOMDocument->getDocumentElement();
>                         if(m_ppRootDOMNode)
>                         {
>                                 TRACE_INFO("Entering
> CSPVXMLParserWrapper::CreateDOMTree() got m_ppRootDOMNode");
>
>                         }
>                         else
>                         {
>                                 TRACE_INFO("Entering
> CSPVXMLParserWrapper::CreateDOMTree() NULL m_ppRootDOMNode");
>
>                                 sifRetCode = ERR_FAILURE;
>                                 m_strErrorString = _T("Exception 
> During Parsing the input XML File.Please check if the XML input 
> conforms to the schema");
>
>                         }
>                         }
>                         else
>                         {
>                         TRACE_INFO("Entering
> CSPVXMLParserWrapper::CreateDOMTree() NULL m_ppDOMDocument");
>                         sifRetCode = ERR_FAILURE;
>                         m_strErrorString = _T("Exception During 
> Parsing the input XML File.Please check if the XML input conforms to 
> the schema");
>
>                         }
>
>}
>
>When we run a memory validation tool on this code, memory leaks are 
>reported
>
>Can you pls let me know if what we're doing in this piece of code is 
>not correct. And how it must be done.
>We want to parse an XML String and generate the DOMdocument and root 
>pointers for referencing the DOM.
>
>Pls reply soon.
>
>Thanks and best regards,
>Pranav
>
>The new company Nokia Siemens Networks is expected to start operations 
>by January 1, 2007, subject to customary regulatory approvals, the 
>completion of standard closing conditions, and the agreement of a 
>number of detailed implementation steps.
>
>Disclaimer:
>This e-mail may contain trade secrets or privileged, undisclosed or 
>otherwise confidential information. If you have received this e-mail in

>error, you are hereby notified that any review, copying or distribution

>of it is strictly prohibited. Please inform us immediately and destroy 
>the original transmittal. Thank you for your cooperation.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org



The new company Nokia Siemens Networks is expected to start operations by January 1, 2007, subject to customary regulatory approvals, the completion of standard closing conditions, and the agreement of a number of detailed implementation steps.

Disclaimer:
This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal. Thank you for your cooperation.

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org