diff --git a/src/xercesc/dom/impl/DOMElementImpl.cpp b/src/xercesc/dom/impl/DOMElementImpl.cpp index 2d9894c1a21135c6cf83b7e0f692ab1eed5a3abd..715cc6487677afab87cdc4e242b7361998ed64a2 100644 --- a/src/xercesc/dom/impl/DOMElementImpl.cpp +++ b/src/xercesc/dom/impl/DOMElementImpl.cpp @@ -477,7 +477,17 @@ void DOMElementImpl::release() DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument; if (doc) { fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0); + // release children fParent.release(); + // release attributes + fAttributes->hasDefaults(false); + XMLSize_t count; + while((count = fAttributes->getLength()) != 0) + { + DOMNode* attr = fAttributes->removeNamedItemAt(count-1); + attr->release(); + } + doc->release(this, DOMMemoryManager::ELEMENT_OBJECT); } else { diff --git a/tests/src/DOM/DOMTest/DTest.cpp b/tests/src/DOM/DOMTest/DTest.cpp index c99aa120430a7b9e9e6939139b098e15f7fff692..85ab26edb99a9004adcd2442f26dcf963f450438 100644 --- a/tests/src/DOM/DOMTest/DTest.cpp +++ b/tests/src/DOM/DOMTest/DTest.cpp @@ -916,6 +916,33 @@ int main(int /*argc*/, char ** /*argv*/) DOMTest::testDocumentFragmentNode = 0; DOMTest::testNotationNode = 0; + // test release of attributes + DOMElement* elt = d->createElement(tempStr3); + elt->setAttribute(tempStr3, tempStr3); + elt->release(); + + elt = d->createElement(tempStr3); + DOMAttr *attr = d->createAttribute(tempStr3); + attr->setValue(tempStr3); + elt->setAttributeNode(attr); + elt->setIdAttributeNode(attr, true); + + DOMElement *eleTest = d->getElementById(tempStr3); + if(eleTest==NULL) + { + fprintf(stderr, "getElementById test failed at line %i\n", __LINE__); + OK = false; + } + + //all good until here + elt->release(); + eleTest = d->getElementById(tempStr3); + if(eleTest!=NULL) + { + fprintf(stderr, "getElementById test failed at line %i\n", __LINE__); + OK = false; + } + // we couldn't really test the user data handler call as the userhandler is already // deleted when the release() is done, but still set it to test the code internally d->setUserData(tempStr, (void*) tempStr, &userhandler);