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 Abhinav Kishore Srivastava <Ab...@infosys.com> on 2009/06/15 12:55:51 UTC

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***

Re: Regd issue : Memory leak in 'Parse' function of DOMParser

Posted by David Bertoni <db...@apache.org>.
Abhinav Kishore Srivastava wrote:
> Dear David Bertoni,
> 
> Thanks for the suggestion. I removed the 'new' call from my code and created the object of membuf and XercesDOMParser as you suggested but still there is a memory leak. After the analysis of the process log I saw that the memory leak is happening when I am calling "m_domParser->parse(membuf);". I guess the memory allocated while parsing is not getting released. 
> 
> Can you suggest me the different ways to release the memory allocated with parsing? To be of safer side I am calling the following after the 'parse' function -
> 
> DOMDocument*	m_doc;
> 
> m_doc = m_domParser->adoptDocument();
> 
> if (m_domParser!=0)
> {
> 	m_domParser = 0;
> }
> 
> if(m_doc!=0)
>         {
>                 m_doc->release();
>                 delete m_doc;
>                 m_doc = 0;
I can't believe this will work.  You can't call delete on m_doc and not 
corrupt the heap of your application. You must only use m_doc->release();

Any decent heap debugger will report this as a problem.  You should see 
if your platform supports heap debugging.  On Linux, you can use 
Valgrind with the memcheck tool.  On Windows, an application linked with 
the debug C run-time will report such errors.  On AIX, there are 
environment variables you can set to control heap debugging.

Note that all of these previous heap checking tools also support dumping 
  leaked memory blocks.  I urge you to consider using such a tool, as it 
will save you a lot of time and effort.

Dave

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


RE: Regd issue : Memory leak in 'Parse' function of DOMParser

Posted by Abhinav Kishore Srivastava <Ab...@infosys.com>.
Dear Alberto,

Thanks for the suggestion.

By default the validation in my application is set as OFF. Also I commented the code where I was setting the custom error handler -

//m_errorHandler = new ParserErrorHandler();

And commented its use also in the later part of the code.

Even after doing this I can't see and decrease in the memory leak. It is just like before. I believe the memory related with parsing (parse tree) is not getting released as I can see the increase in process size just after the 'Parse' function of XercesDOMParser is called. And the size id not decreasing instead it is increasing with more tests being run.

Can you suggest ways to release any memory allocated with parsing?


Thanks,
Abhinav Kishore

-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com] 
Sent: Thursday, June 18, 2009 5:15 PM
To: c-dev@xerces.apache.org
Cc: dbertoni@apache.org
Subject: Re: Regd issue : Memory leak in 'Parse' function of DOMParser

Can you try running with validation turned off and without setting your 
custom error handler?

Alberto

Abhinav Kishore Srivastava wrote:
> Dear David Bertoni,
>
> Thanks for the suggestion. I removed the 'new' call from my code and created the object of membuf and XercesDOMParser as you suggested but still there is a memory leak. After the analysis of the process log I saw that the memory leak is happening when I am calling "m_domParser->parse(membuf);". I guess the memory allocated while parsing is not getting released. 
>
> Can you suggest me the different ways to release the memory allocated with parsing? To be of safer side I am calling the following after the 'parse' function -
>
> DOMDocument*	m_doc;
>
> m_doc = m_domParser->adoptDocument();
>
> if (m_domParser!=0)
> {
> 	m_domParser = 0;
> }
>
> if(m_doc!=0)
>         {
>                 m_doc->release();
>                 delete m_doc;
>                 m_doc = 0;
>          
>         }
>
>
> But this is not helping at all and memory is leaking like it used to be earlier.
>
>
> Thanks,
> Abhinav Kishore
>
> -----Original Message-----
> From: David Bertoni [mailto:dbertoni@apache.org] 
> Sent: Wednesday, June 17, 2009 11:19 PM
> To: c-dev@xerces.apache.org
> Subject: Re: Regd issue : Memory leak in 'Parse' function of DOMParser
>
> Abhinav Kishore Srivastava wrote:
>   
>> Hi,
>>
>> Does that mean I don't have to create the parser and membuf objet with 'new'?? If not then how should I create it? In my application the same process receives request for xml parsing at different times. Each time I am creating a new object of parser and then deleting it too.
>>     
> You can create them on the stack:
>
> MemBufInputSource membuf(
>      (const XMLByte*)theString.data(),
>      theString.size(),
>      "APIXMLInterface",
>      false);
>
> XercesDOMParser localParser;
>
> m_domParser = &localParser;
>
> ...
>
> m_domParser = 0;
>
> Although I don't know if that will help much, since the parser will 
> allocate memory dynamically regardless.
>
>   
>> Also, I checked my process giving it a bad input. In that case the process gets core dump releasing all the memory acquired. 
>>     
> Why does your application core dump on bad input?  The parser shouldn't 
> do that.
>
> None of your evidence proves the Xerces-C library is leaking memory.  I 
> suggest you test the parser code outside of your application to verify 
> if there is a memory leak.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
> **************** 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: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
>   


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


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


Re: Regd issue : Memory leak in 'Parse' function of DOMParser

Posted by Alberto Massari <am...@datadirect.com>.
Can you try running with validation turned off and without setting your 
custom error handler?

Alberto

Abhinav Kishore Srivastava wrote:
> Dear David Bertoni,
>
> Thanks for the suggestion. I removed the 'new' call from my code and created the object of membuf and XercesDOMParser as you suggested but still there is a memory leak. After the analysis of the process log I saw that the memory leak is happening when I am calling "m_domParser->parse(membuf);". I guess the memory allocated while parsing is not getting released. 
>
> Can you suggest me the different ways to release the memory allocated with parsing? To be of safer side I am calling the following after the 'parse' function -
>
> DOMDocument*	m_doc;
>
> m_doc = m_domParser->adoptDocument();
>
> if (m_domParser!=0)
> {
> 	m_domParser = 0;
> }
>
> if(m_doc!=0)
>         {
>                 m_doc->release();
>                 delete m_doc;
>                 m_doc = 0;
>          
>         }
>
>
> But this is not helping at all and memory is leaking like it used to be earlier.
>
>
> Thanks,
> Abhinav Kishore
>
> -----Original Message-----
> From: David Bertoni [mailto:dbertoni@apache.org] 
> Sent: Wednesday, June 17, 2009 11:19 PM
> To: c-dev@xerces.apache.org
> Subject: Re: Regd issue : Memory leak in 'Parse' function of DOMParser
>
> Abhinav Kishore Srivastava wrote:
>   
>> Hi,
>>
>> Does that mean I don't have to create the parser and membuf objet with 'new'?? If not then how should I create it? In my application the same process receives request for xml parsing at different times. Each time I am creating a new object of parser and then deleting it too.
>>     
> You can create them on the stack:
>
> MemBufInputSource membuf(
>      (const XMLByte*)theString.data(),
>      theString.size(),
>      "APIXMLInterface",
>      false);
>
> XercesDOMParser localParser;
>
> m_domParser = &localParser;
>
> ...
>
> m_domParser = 0;
>
> Although I don't know if that will help much, since the parser will 
> allocate memory dynamically regardless.
>
>   
>> Also, I checked my process giving it a bad input. In that case the process gets core dump releasing all the memory acquired. 
>>     
> Why does your application core dump on bad input?  The parser shouldn't 
> do that.
>
> None of your evidence proves the Xerces-C library is leaking memory.  I 
> suggest you test the parser code outside of your application to verify 
> if there is a memory leak.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
> **************** 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: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
>   


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


RE: Regd issue : Memory leak in 'Parse' function of DOMParser

Posted by Abhinav Kishore Srivastava <Ab...@infosys.com>.
Dear David Bertoni,

Thanks for the suggestion. I removed the 'new' call from my code and created the object of membuf and XercesDOMParser as you suggested but still there is a memory leak. After the analysis of the process log I saw that the memory leak is happening when I am calling "m_domParser->parse(membuf);". I guess the memory allocated while parsing is not getting released. 

Can you suggest me the different ways to release the memory allocated with parsing? To be of safer side I am calling the following after the 'parse' function -

DOMDocument*	m_doc;

m_doc = m_domParser->adoptDocument();

if (m_domParser!=0)
{
	m_domParser = 0;
}

if(m_doc!=0)
        {
                m_doc->release();
                delete m_doc;
                m_doc = 0;
         
        }


But this is not helping at all and memory is leaking like it used to be earlier.


Thanks,
Abhinav Kishore

-----Original Message-----
From: David Bertoni [mailto:dbertoni@apache.org] 
Sent: Wednesday, June 17, 2009 11:19 PM
To: c-dev@xerces.apache.org
Subject: Re: Regd issue : Memory leak in 'Parse' function of DOMParser

Abhinav Kishore Srivastava wrote:
> Hi,
> 
> Does that mean I don't have to create the parser and membuf objet with 'new'?? If not then how should I create it? In my application the same process receives request for xml parsing at different times. Each time I am creating a new object of parser and then deleting it too.
You can create them on the stack:

MemBufInputSource membuf(
     (const XMLByte*)theString.data(),
     theString.size(),
     "APIXMLInterface",
     false);

XercesDOMParser localParser;

m_domParser = &localParser;

...

m_domParser = 0;

Although I don't know if that will help much, since the parser will 
allocate memory dynamically regardless.

> 
> Also, I checked my process giving it a bad input. In that case the process gets core dump releasing all the memory acquired. 
Why does your application core dump on bad input?  The parser shouldn't 
do that.

None of your evidence proves the Xerces-C library is leaking memory.  I 
suggest you test the parser code outside of your application to verify 
if there is a memory leak.

Dave

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


**************** 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: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Regd issue : Memory leak in 'Parse' function of DOMParser

Posted by David Bertoni <db...@apache.org>.
Abhinav Kishore Srivastava wrote:
> Hi,
> 
> Does that mean I don't have to create the parser and membuf objet with 'new'?? If not then how should I create it? In my application the same process receives request for xml parsing at different times. Each time I am creating a new object of parser and then deleting it too.
You can create them on the stack:

MemBufInputSource membuf(
     (const XMLByte*)theString.data(),
     theString.size(),
     "APIXMLInterface",
     false);

XercesDOMParser localParser;

m_domParser = &localParser;

...

m_domParser = 0;

Although I don't know if that will help much, since the parser will 
allocate memory dynamically regardless.

> 
> Also, I checked my process giving it a bad input. In that case the process gets core dump releasing all the memory acquired. 
Why does your application core dump on bad input?  The parser shouldn't 
do that.

None of your evidence proves the Xerces-C library is leaking memory.  I 
suggest you test the parser code outside of your application to verify 
if there is a memory leak.

Dave

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


RE: Regd issue : Memory leak in 'Parse' function of DOMParser

Posted by Abhinav Kishore Srivastava <Ab...@infosys.com>.
Hi,

Does that mean I don't have to create the parser and membuf objet with 'new'?? If not then how should I create it? In my application the same process receives request for xml parsing at different times. Each time I am creating a new object of parser and then deleting it too.

Also, I checked my process giving it a bad input. In that case the process gets core dump releasing all the memory acquired. 

Please help.

Thanks,
Abhinav Kishore


-----Original Message-----
From: Tobias [mailto:ubub@gmx.net] 
Sent: Tuesday, June 16, 2009 1:05 PM
To: c-dev@xerces.apache.org
Subject: Re: Regd issue : Memory leak in 'Parse' function of DOMParser

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" <Ab...@infosys.com>
To: <c-...@xerces.apache.org>
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: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


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


Re: Regd issue : Memory leak in 'Parse' function of DOMParser

Posted by Tobias <ub...@gmx.net>.
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" <Ab...@infosys.com>
To: <c-...@xerces.apache.org>
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: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


RE: Regd issue : Memory leak in 'Parse' function of DOMParser

Posted by Abhinav Kishore Srivastava <Ab...@infosys.com>.
Dear David Bertoni,

The reason why I think Xerces is leaking is - I can see memory allocation at the time when " m_domParser->parse(*membuf);" function is called and this memory is never released. The size of the process increases by the amount of memory allocated at this point.

As my process never terminates and keeps on running all the time i.e. taking request-processing-giving the response, so earlier it was assumed that it is normal C runtime heap allocation (and caching) but then it was found that the process size is increasing everyday. At the time of start of process the size is 61Mb but it has grown to 1.5Gb which made restart of process inevitable.

Please note that the memory is not leaking every time this piece of code is called. Also the pattern of leak is also not fixed. Sometimes the allocation on heap is 16Kb and sometimes it is 128Kb and sometimes there is no memory leak. Also please note that there is no loop on this code. This is called when our process receives a request to process and XML. For each request we are creating a new object of XercesDOMParser with 'new' and after the required XML is processed we are deleting the object there by releasing the memory. 

Please suggest if I am forgetting to call any release function or any other function which will release the memory.


Thanks,
Abhinav Kishore


-----Original Message-----
From: David Bertoni [mailto:dbertoni@apache.org] 
Sent: Monday, June 15, 2009 10:44 PM
To: c-dev@xerces.apache.org
Subject: Re: Regd issue : Memory leak in 'Parse' function of DOMParser

Abhinav Kishore Srivastava wrote:
> 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:_*
> 
...
> 
>                                 *m_domParser->parse(*membuf); //memory 
> utilization increases here and later on when delete m_domParser is 
> called, it is not released.*
Are you sure that Xerces-C is leaking?  It's common for the C run-time 
heap implementation to keep memory that you've freed cached for future 
allocations.

What happens when you run this code in a loop for a thousand interations 
  or so?  Does memory usage keep increasing, or does it remain stable?

Dave

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


**************** 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: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Regd issue : Memory leak in 'Parse' function of DOMParser

Posted by David Bertoni <db...@apache.org>.
Abhinav Kishore Srivastava wrote:
> 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:_*
> 
...
> 
>                                 *m_domParser->parse(*membuf); //memory 
> utilization increases here and later on when delete m_domParser is 
> called, it is not released.*
Are you sure that Xerces-C is leaking?  It's common for the C run-time 
heap implementation to keep memory that you've freed cached for future 
allocations.

What happens when you run this code in a loop for a thousand interations 
  or so?  Does memory usage keep increasing, or does it remain stable?

Dave

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