You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by 91change <91...@gmail.com> on 2009/03/25 19:49:04 UTC

Memory Leaking in xerces-2.8.0

Please find my consttuctor and distructor 

XMLConfig::XMLConfig()
{


        try
        {
                XMLPlatformUtils::Initialize();
                
        }
        catch( XMLException& e )
        {
               
        }
        m_ConfigFileParser = new XercesDOMParser;
}

XMLConfig::~XMLConfig()
{
        try
        {
                // Terminate Xerces   
                XMLPlatformUtils::Terminate();

        } catch( xercesc::XMLException& e )
        {
             
        }

}



i will create only 3 or 4  XMLConfig object and use  different 
m_ConfigFileParser to parse multiple files .... (more than 10 ) 


 m_ConfigFileParser->setErrorHandler(NULL);
       
m_ConfigFileParser->setValidationScheme(XercesDOMParser::Val_Always);
        m_ConfigFileParser->setDoNamespaces( true);
        m_ConfigFileParser->setDoSchema( true);
        m_ConfigFileParser->setValidationSchemaFullChecking(true);
        m_ConfigFileParser->setDoValidation(true);
          cout<<endl<<"Before parse called"<<endl;
              m_ConfigFileParser->parse( configFile.c_str() )

I am getting a lot of memory leak .......How can i avoid that ....
If i try to delete(m_ConfigFileParser) ...There is a segmentation fault
happening ...

Please help .
-- 
View this message in context: http://www.nabble.com/Memory-Leaking-in-xerces-2.8.0-tp22707783p22707783.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Help! DTD Grammar not being cached ...

Posted by Ben Griffin <be...@redsnapper.net>.
I've really tried to find out what I am doing wrong here.
Basically, I am using my own DOMLSResourceResolver to use a local copy  
of XHTML 1.1 Strict DTD for many hundreds of XHTML documents.
But the parser seems to be refusing to cache it, or find it - so it is  
asking for a new copy for each document.

I am sure I am doing something wrong - but what I noticed was that  
srcToFill->getSystemId() is not returning the SystemID that I set.

Here are the parser settings I am using.
dc->setParameter(XMLUni::fgDOMResourceResolver,myResourceHandler);
	
dc->setParameter(XMLUni::fgXercesValidationErrorAsFatal, false);		
dc->setParameter(XMLUni::fgXercesUserAdoptsDOMDocument, true);		
dc->setParameter(XMLUni::fgXercesUseCachedGrammarInParse, true);		
dc->setParameter(XMLUni::fgXercesSchema, true);	
dc->setParameter(XMLUni::fgXercesSchemaFullChecking, true);	
dc->setParameter(XMLUni::fgXercesContinueAfterFatalError, true);		
dc->setParameter(XMLUni::fgXercesCacheGrammarFromParse, true);		
dc->setParameter(XMLUni::fgDOMElementContentWhitespace, false); 	
dc->setParameter(XMLUni::fgDOMNamespaces, true);
dc->setParameter(XMLUni::fgDOMDatatypeNormalization, true);
dc->setParameter(XMLUni::fgXercesLoadExternalDTD, false);
dc->setParameter(XMLUni::fgXercesIgnoreCachedDTD, false);
dc->setParameter(XMLUni::fgDOMValidateIfSchema, true);

My call traces were as follows:

void TraverseSchema::preprocessImport(const DOMElement* const elem)

         InputSource* srcToFill =  
resolveSchemaLocation 
(schemaLocation,XMLResourceIdentifier::SchemaImport, nameSpace);

(which goes to)

InputSource* TraverseSchema::resolveSchemaLocation(const XMLCh* const  
loc,
                                 const  
XMLResourceIdentifier::ResourceIdentifierType resourceIdentitiferType,
                                 const XMLCh* const nameSpace)


(which goes to)

  InputSource* DOMLSParserImpl::resolveEntity( XMLResourceIdentifier*  
resourceIdentifier ) {
      if (fEntityResolver) {
         DOMLSInput* is = fEntityResolver- 
 > 
resolveResource 
(resourceIdentifier 
 >getResourceIdentifierType()==XMLResourceIdentifier::ExternalEntity? 
XMLUni::fgDOMDTDType:XMLUni::fgDOMXMLSchemaType,
                  resourceIdentifier->getNameSpace(),
                  resourceIdentifier->getPublicId(),
                  resourceIdentifier->getSystemId(),
                 resourceIdentifier->getBaseURI());
         if (is)
             return new (getMemoryManager()) Wrapper4DOMLSInput(is,  
fEntityResolver, true, getMemoryManager());
     }
     if (fXMLEntityResolver) {
         return(fXMLEntityResolver->resolveEntity(resourceIdentifier));
     }
     return 0;
}

//DOMLSParserImpl::resolveEntity calls my resolveResource which I have  
added using XMLUni::fgDOMResourceResolver
//where I construct a new DOMLSInput with createLSInput //which  
contains, in this case, a local copy of XHTML 1.1 Strict DTD.
[...]
	DOMLSInput* srcToFill = ((DOMImplementationLS*)Manager::parser()- 
 >impl)->createLSInput();		
	srcToFill->setStringData(my_dtd_xhtml1_grammar);  //This DTD is  
already XMLCh encoded, and is definitely correct.
	srcToFill->setEncoding(XMLUni::fgXMLChEncodingString);
	srcToFill->setPublicId(publicId);
	srcToFill->setSystemId(systemId);
	return srcToFill;
[...]

The returned LSInput bubbles back upt to preprocessImport,

TraverseSchema, Line 830:
     const XMLCh* importURL = srcToFill->getSystemId();  <<-- returns  
NULL even though I set it in the DOMLSInput.



Re: createTextNode performing unexpected XML encoding.

Posted by Ben Griffin <be...@redsnapper.net>.
Dave, thanks for your assistance on this.

Re: createTextNode performing unexpected XML encoding.

Posted by David Bertoni <db...@apache.org>.
Ben Griffin wrote:
> Is it correct that createTextNode should XML Encode the DOMString passed 
> to it?
I'm going to assume by "XML Encode" you mean to escape any markup 
characters. If that's the case, the answer is no.

> To me, w3 implies that the text should be parsed as if it is xml already.
> http://www.w3.org/TR/DOM-Level-2-Core/core.html
> Text  createTextNode(in DOMString data);
> "The Text interface inherits from CharacterData and represents the 
> textual content (termed character data in XML) of an Element or Attr. If 
> there is no markup inside an element's content, the text is contained in 
> a single object implementing the Text interface that is the only child 
> of the element. If there is markup, it is parsed into the information 
> items (elements, comments, etc.) and Text nodes that form the list of 
> children of the element."
The value of a text node is _not_ markup, so markup characters will not 
be escaped.

> 
> 
> DomDocument says nothing about this:
>     /**
>      * Creates a <code>DOMText</code> node given the specified string.
>      * @param data The data for the node.
>      * @return The new <code>DOMText</code> object.
>      * @since DOM Level 1
>      */
>     virtual DOMText         *createTextNode(const XMLCh *data) = 0;
> 
> XMLCh* newval = X("Mum &amp; Dad");
You are creating a string with 13 characters.

> DOMText* vt = doc->createTextNode(newval);
> 
> vt now contains "Mum &amp;amp; Dad"
When you say "vt now contains" that string, how are you checking that? 
I would expect this to occur if you serialized the document, but not if 
you were viewing it in a debugger, or through a binary dump.

> How may I create a TextNode that knows that the XMLCh* is already 
> xml-encoded?
You can't.

> 
> This is relevant, as I may have dynamically extracted the XMLCh* from 
> existing xml.
I don't know what you mean by this statement.  Character data in a text 
node is not markup, it's character data.  As long as you are copying 
data from one text node to another, there's nothing special you need to do.

What you cannot do is put markup in a text node and expect that it will 
be treated as markup.

Dave


createTextNode performing unexpected XML encoding.

Posted by Ben Griffin <be...@redsnapper.net>.
Is it correct that createTextNode should XML Encode the DOMString  
passed to it?
To me, w3 implies that the text should be parsed as if it is xml  
already.
http://www.w3.org/TR/DOM-Level-2-Core/core.html
Text  createTextNode(in DOMString data);
"The Text interface inherits from CharacterData and represents the  
textual content (termed character data in XML) of an Element or Attr.  
If there is no markup inside an element's content, the text is  
contained in a single object implementing the Text interface that is  
the only child of the element. If there is markup, it is parsed into  
the information items (elements, comments, etc.) and Text nodes that  
form the list of children of the element."


DomDocument says nothing about this:
     /**
      * Creates a <code>DOMText</code> node given the specified string.
      * @param data The data for the node.
      * @return The new <code>DOMText</code> object.
      * @since DOM Level 1
      */
     virtual DOMText         *createTextNode(const XMLCh *data) = 0;

XMLCh* newval = X("Mum &amp; Dad");		
DOMText* vt = doc->createTextNode(newval);

vt now contains "Mum &amp;amp; Dad"

How may I create a TextNode that knows that the XMLCh* is already xml- 
encoded?

This is relevant, as I may have dynamically extracted the XMLCh* from  
existing xml.



RE: Memory Leaking in xerces-2.8.0

Posted by 91change <91...@gmail.com>.

Jesse Pelton ,

        thanks  a Ton ...


  Now there  is no memmory leak  in my code .
  
  I have made following changes .. Someone my find it helpful ...

   1) Called  XmlPlatformUtils::Initialize()   only once .
   2)  not  called   delete(m_ConfigFileParser)  anywhere  ....Calle
Terminate() when process ends (once ) ....
   3)  not used  reset() , release() , resetDocumentPool() anywhere in code
..Eventhough i am using one m_ConfigFileParser to parse multiple files 
   4)      Use xerces-2.8 


-- 
View this message in context: http://www.nabble.com/Memory-Leaking-in-xerces-2.8.0-tp22707783p22719722.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


RE: Memory Leaking in xerces-2.8.0

Posted by Jesse Pelton <js...@PKC.com>.
The XmlPlatformUtils::Initialize() description in the documentation:
"Perform per-process parser initialization."  This means you should call
Initialize() once per process; likewise for Terminate().  Calling the
functions multiple times in a process could cause the behavior you're
seeing, especially if you're calling them from multiple threads.

-----Original Message-----
From: 91change [mailto:91change@gmail.com] 
Sent: Wednesday, March 25, 2009 2:49 PM
To: c-users@xerces.apache.org
Subject: Memory Leaking in xerces-2.8.0


Please find my consttuctor and distructor 

XMLConfig::XMLConfig()
{


        try
        {
                XMLPlatformUtils::Initialize();
                
        }
        catch( XMLException& e )
        {
               
        }
        m_ConfigFileParser = new XercesDOMParser;
}

XMLConfig::~XMLConfig()
{
        try
        {
                // Terminate Xerces   
                XMLPlatformUtils::Terminate();

        } catch( xercesc::XMLException& e )
        {
             
        }

}



i will create only 3 or 4  XMLConfig object and use  different 
m_ConfigFileParser to parse multiple files .... (more than 10 ) 


 m_ConfigFileParser->setErrorHandler(NULL);
       
m_ConfigFileParser->setValidationScheme(XercesDOMParser::Val_Always);
        m_ConfigFileParser->setDoNamespaces( true);
        m_ConfigFileParser->setDoSchema( true);
        m_ConfigFileParser->setValidationSchemaFullChecking(true);
        m_ConfigFileParser->setDoValidation(true);
          cout<<endl<<"Before parse called"<<endl;
              m_ConfigFileParser->parse( configFile.c_str() )

I am getting a lot of memory leak .......How can i avoid that ....
If i try to delete(m_ConfigFileParser) ...There is a segmentation fault
happening ...

Please help .
-- 
View this message in context:
http://www.nabble.com/Memory-Leaking-in-xerces-2.8.0-tp22707783p22707783
.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.