Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-2145

indefinite memory allocations using DOMNode::getTextContent()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Bug
    • 3.1.2, 3.2.1
    • None
    • DOM
    • None
    • Windows 10, Visual Studio 2017

    Description

      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: 

      #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);
         }
      }
      

      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.

      Attachments

        1. main.cpp
          1 kB
          Blair Fonville
        2. config.xml
          0.2 kB
          Blair Fonville

        Activity

          People

            Unassigned Unassigned
            blair.fonville Blair Fonville
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: