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 "Wuebben, Anthony E. (LNG)" <An...@lexisnexis.com> on 2002/06/04 23:02:12 UTC

Memory leak when setCreateEntityReferenceNodes is true

I'm running on Solaris 5.7 with xerces 1.7 and I am seeing the following
problem:

My long running applications are leaking what appears to be the entire DOM
tree when setCreateEntityReferenceNodes() is set to true and the XML file
being parsed contains a entity reference.  If I turn off the creatation of
entity references or pass in a file that does not contain entity-reference
everything is fine.

Any help would be appreciated. 

Below is a sample of the code that fails. Just give it the below document
that contains an entity-reference and it leaks.


CODE
while(1) {
 
    try {
        fprintf(stderr,"Calling XMLPlatformUtils::Initialize()\n");
        XMLPlatformUtils::Initialize();
        }
    catch(const XMLException& toCatch) {
        char *cp = XMLString::transcode(toCatch.getMessage());
        fprintf(stderr,"Error during Xerces-c Initialization: [%s]\n",cp);
        delete [] cp;
        return 1;
        }
 
         DOMParser * _parser = new DOMParser;
 
        _parser->setDoValidation(false);
        _parser->setValidationScheme(DOMParser::Val_Never);
        _parser->setCreateEntityReferenceNodes(true);
        _parser->setToCreateXMLDeclTypeNode(true);
        _parser->setIncludeIgnorableWhitespace(true);
        _parser->setDoNamespaces(false);
 
       _parser->parse(filename);
  
        delete _parser;

    try {
        fprintf(stderr,"Calling XMLPlatformUtils::Terminate()\n");
        XMLPlatformUtils::Terminate();
        }
    catch(const XMLException& toCatch) {
        char *cp = XMLString::transcode(toCatch.getMessage());
        fprintf(stderr,"Error during Xerces-c Termination: [%s]\n",cp);
        delete [] cp;
        }
} // end forever
        exit(0);
}

FILE
<!DOCTYPE foo [ 
        <!ELEMENT foo (foo1|foo2) >
        <!ELEMENT foo1 (#PCDATA)* >
        <!ELEMENT foo2 (#PCDATA)* >
<!ENTITY entityfoo "entity-value">
]>
<foo><foo1>This a some test data &entityfoo; and more test data
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn</foo1></foo>



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


Re: Memory leak when setCreateEntityReferenceNodes is true

Posted by PeiYong PY Zhang <pe...@ca.ibm.com>.
Anthony,

    If you link your test code with the latest nightly build, and use the
XercesDOMParser,
instead of the DOMParser, then the leakage is no longer there.

    It seems that the new dom (known as Idom previously) has solved the
problem in the
deprecated dom (known as dom previously).

Rgds,
PeiYong



"Wuebben, Anthony E. (LNG)" wrote:

> I'm running on Solaris 5.7 with xerces 1.7 and I am seeing the following
> problem:
>
> My long running applications are leaking what appears to be the entire DOM
> tree when setCreateEntityReferenceNodes() is set to true and the XML file
> being parsed contains a entity reference.  If I turn off the creatation of
> entity references or pass in a file that does not contain entity-reference
> everything is fine.
>
> Any help would be appreciated.
>
> Below is a sample of the code that fails. Just give it the below document
> that contains an entity-reference and it leaks.
>
> CODE
> while(1) {
>
>     try {
>         fprintf(stderr,"Calling XMLPlatformUtils::Initialize()\n");
>         XMLPlatformUtils::Initialize();
>         }
>     catch(const XMLException& toCatch) {
>         char *cp = XMLString::transcode(toCatch.getMessage());
>         fprintf(stderr,"Error during Xerces-c Initialization: [%s]\n",cp);
>         delete [] cp;
>         return 1;
>         }
>
>          DOMParser * _parser = new DOMParser;
>
>         _parser->setDoValidation(false);
>         _parser->setValidationScheme(DOMParser::Val_Never);
>         _parser->setCreateEntityReferenceNodes(true);
>         _parser->setToCreateXMLDeclTypeNode(true);
>         _parser->setIncludeIgnorableWhitespace(true);
>         _parser->setDoNamespaces(false);
>
>        _parser->parse(filename);
>
>         delete _parser;
>
>     try {
>         fprintf(stderr,"Calling XMLPlatformUtils::Terminate()\n");
>         XMLPlatformUtils::Terminate();
>         }
>     catch(const XMLException& toCatch) {
>         char *cp = XMLString::transcode(toCatch.getMessage());
>         fprintf(stderr,"Error during Xerces-c Termination: [%s]\n",cp);
>         delete [] cp;
>         }
> } // end forever
>         exit(0);
> }
>
> FILE
> <!DOCTYPE foo [
>         <!ELEMENT foo (foo1|foo2) >
>         <!ELEMENT foo1 (#PCDATA)* >
>         <!ELEMENT foo2 (#PCDATA)* >
> <!ENTITY entityfoo "entity-value">
> ]>
> <foo><foo1>This a some test data &entityfoo; and more test data
> nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn</foo1></foo>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


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