[ 
https://issues.apache.org/jira/browse/XERCESC-2145?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16427778#comment-16427778
 ] 

Scott Cantor commented on XERCESC-2145:
---------------------------------------

No, it's not a bug. That is a known behavior of the library and if that's what 
you're doing, then you are going to have to change your code.

That aside, getTextContent does not work anyway. It's buggy as all get out and 
is effectively useless. You can't read the DOM that way or you'll get 
inaccurate data back under a variety of different circumstances if there are 
non-adjacent Text nodes (and if there aren't, you don't need to use it anyway 
since the direct node value will be all you need).

You should use getNodeValue, and that returns a pointer to the data, rather 
than reallocating it off an internal heap. If you need to accomodate 
non-adjacent text nodes, then you should combine them yourself at runtime using 
memory you can manage.

> indefinite memory allocations using DOMNode::getTextContent()
> -------------------------------------------------------------
>
>                 Key: XERCESC-2145
>                 URL: https://issues.apache.org/jira/browse/XERCESC-2145
>             Project: Xerces-C++
>          Issue Type: Bug
>          Components: DOM
>    Affects Versions: 3.1.2, 3.2.1
>         Environment: Windows 10, Visual Studio 2017
>            Reporter: Blair Fonville
>            Priority: Major
>         Attachments: config.xml, main.cpp
>
>
> In a program which reads (parses) an xml file once into a DOMDocument, and 
> then accesses the content of the nodes/elements often, through 
> getTextContent(), the heap memory builds indefinitely.
> For example: 
> {code:java}
> #include <xercesc/dom/DOM.hpp>
> XERCES_CPP_NAMESPACE_USE
> int main(int argc, char **argv)
> {
>    XMLPlatformUtils::Initialize();
>    XMLCh tempStr[100];
>    XMLString::transcode("LS", tempStr, 99);
>    DOMImplementation *impl = 
> DOMImplementationRegistry::getDOMImplementation(tempStr);
>    DOMLSParser *parser = ((DOMImplementationLS*)impl) ->createLSParser( 
> DOMImplementationLS::MODE_SYNCHRONOUS, 0);
>    DOMDocument *doc = impl->createDocument(0, 0, 0);
>    doc = parser->parseURI("config.xml");
>    DOMElement *el = doc->getDocumentElement();
>    // Heap blows up here
>    while (1) {
>       char *cstr = XMLString::transcode(el->getTextContent());
>       XMLString::release(&cstr);
>    }
>    // and/or here
>    while (1) {
>       XMLCh *xstr = XMLString::replicate(el->getTextContent());
>       char *cstr = XMLString::transcode(xstr);
>       XMLString::release(&cstr);
>       XMLString::release(&xstr);
>    }
> }
> {code}
> I realize that the memory is supposed to be freed when the Document is 
> released, but in a program where the Document is populated at startup, and 
> used forever, this is, for all practical purposes, a memory leak. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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

Reply via email to