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

Memory leaks in DOMDocumentImpl

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.6.0
    • 2.7.0
    • DOM
    • None
    • Win XP, VS.NET 2k3

    Description

      Hi,

      I wanted to use xerces and DOMDocument as kind of dynamical XML fragments container. I want to add new and remove old unused XML elements, but i have encountered that the memory usage is increasing without any apparent reason. If i want to remove the element i wanted to use following code:

      DOMNode* pNode = pParent->removeChild(pElement);
      pNode->release();

      By the documentation, all the memory should be marked as usable for feature use, but that is not true, because the attributes are not released and memory usage is increasing. So I modified the code as follows:

      DOMNode* pNode = pParent->removeChild(pElement);

      DOMNamedNodeMap* pAttributes = pElement->getAttributes();
      while(pAttributes->getLength() != 0)

      { DOMAttr* pAttr = pElement->removeAttributeNode((DOMAttr*) pAttributes->item(0)); pAttr->release(); }

      pNode->release();

      This code will release the node with its attributes, but still the memory usage is increasing. I have traced the xerces code and found where the problem lies. Its in the method void DOMBuffer::expandCapacity(const unsigned int extraNeeded) which is leaking. The easy solution could be to use the DOMBuffer* DOMDocumentImpl::popBuffer() in a way where the necessary buffer size will be specified and it will return sufficient buffer from fRecycleBufferPtr used or null to create new large enough buffer? I propose something like

      DOMBuffer* DOMDocumentImpl::popBuffer(int nMinLength)
      {
      if (!fRecycleBufferPtr || fRecycleBufferPtr->empty())
      return 0;

      DOMBuffer* first = fRecycleBufferPtr->pop();
      DOMBuffer* buffer = first;
      do
      {
      if (buffer->getLen() >= nMinLength) return buffer;
      else

      { fRecycleBufferPtr->push(buffer); buffer = fRecycleBufferPtr->pop(); }

      }
      while(buffer != first);

      return 0;
      }

      By this code you can avoid the void DOMBuffer::expandCapacity(const unsigned int extraNeeded) call and the memory leaks. What do you think about it?

      Sincerely,

      Vit Ondruch

      Attachments

        Activity

          People

            Unassigned Unassigned
            vo.x Vit Ondruch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: