SVN commit 583314 by orlovich: Fix a number of leaks involving use of removeChild (and replaceChild). Essentially, operations like deleteTHead, deleteTableCell etc., could frequently leak nodes as removeChild would never drop refcount to 0 (just setParent). This changes it to do so; and just the users that need node kept alive to do so. Note tha this also means these ops no longer return the old node, as it's not guaranteed to be alive... Prerequisite for making some latter work sane... M +6 -4 dom/dom_node.cpp M +4 -6 html/html_elementimpl.cpp M +4 -6 html/html_formimpl.cpp M +2 -2 html/html_formimpl.h M +5 -8 html/html_tableimpl.cpp M +2 -2 html/html_tableimpl.h M +2 -0 html/htmlparser.cpp M +22 -17 xml/dom_nodeimpl.cpp M +6 -4 xml/dom_nodeimpl.h --- branches/KDE/3.5/kdelibs/khtml/dom/dom_node.cpp #583313:583314 @@ -270,21 +270,23 @@ { if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR); int exceptioncode = 0; - NodeImpl *r = impl->replaceChild( newChild.impl, oldChild.impl, exceptioncode ); + impl->replaceChild( newChild.impl, oldChild.impl, exceptioncode ); if (exceptioncode) throw DOMException(exceptioncode); if (newChild.impl && !newChild.impl->closed()) newChild.impl->close(); - return r; + + return oldChild; } Node Node::removeChild( const Node &oldChild ) { if (!impl) throw DOMException(DOMException::NOT_FOUND_ERR); int exceptioncode = 0; - NodeImpl *r = impl->removeChild( oldChild.impl, exceptioncode ); + impl->removeChild( oldChild.impl, exceptioncode ); if (exceptioncode) throw DOMException(exceptioncode); - return r; + + return oldChild; } Node Node::appendChild( const Node &newChild ) --- branches/KDE/3.5/kdelibs/khtml/html/html_elementimpl.cpp #583313:583314 @@ -530,28 +530,26 @@ // we need to pop and
elements and remove to // accomadate folks passing complete HTML documents to make the // child of an element. - Node n; - for ( NodeImpl* node = fragment->firstChild(); node; ) { if (node->id() == ID_HTML || node->id() == ID_BODY) { NodeImpl* firstChild = node->firstChild(); NodeImpl* child = firstChild; while ( child ) { NodeImpl *nextChild = child->nextSibling(); - n = fragment->insertBefore(child, node, ignoredExceptionCode); + fragment->insertBefore(child, node, ignoredExceptionCode); child = nextChild; } if ( !firstChild ) { NodeImpl *nextNode = node->nextSibling(); - n = fragment->removeChild(node, ignoredExceptionCode); + fragment->removeChild(node, ignoredExceptionCode); node = nextNode; } else { - n = fragment->removeChild(node, ignoredExceptionCode); + fragment->removeChild(node, ignoredExceptionCode); node = firstChild; } } else if (node->id() == ID_HEAD) { NodeImpl *nextNode = node->nextSibling(); - n = fragment->removeChild(node, ignoredExceptionCode); + fragment->removeChild(node, ignoredExceptionCode); node = nextNode; } else { node = node->nextSibling(); --- branches/KDE/3.5/kdelibs/khtml/html/html_formimpl.cpp #583313:583314 @@ -2211,20 +2211,18 @@ return result; } -NodeImpl *HTMLSelectElementImpl::replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode ) +void HTMLSelectElementImpl::replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode ) { - NodeImpl* const result = HTMLGenericFormElementImpl::replaceChild(newChild,oldChild, exceptioncode); + HTMLGenericFormElementImpl::replaceChild(newChild,oldChild, exceptioncode); if( !exceptioncode ) setRecalcListItems(); - return result; } -NodeImpl *HTMLSelectElementImpl::removeChild ( NodeImpl *oldChild, int &exceptioncode ) +void HTMLSelectElementImpl::removeChild ( NodeImpl *oldChild, int &exceptioncode ) { - NodeImpl* const result = HTMLGenericFormElementImpl::removeChild(oldChild, exceptioncode); + HTMLGenericFormElementImpl::removeChild(oldChild, exceptioncode); if( !exceptioncode ) setRecalcListItems(); - return result; } NodeImpl *HTMLSelectElementImpl::appendChild ( NodeImpl *newChild, int &exceptioncode ) --- branches/KDE/3.5/kdelibs/khtml/html/html_formimpl.h #583313:583314 @@ -413,8 +413,8 @@ virtual void restoreState(const QString &); virtual NodeImpl *insertBefore ( NodeImpl *newChild, NodeImpl *refChild, int &exceptioncode ); - virtual NodeImpl *replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode ); - virtual NodeImpl *removeChild ( NodeImpl *oldChild, int &exceptioncode ); + virtual void replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode ); + virtual void removeChild ( NodeImpl *oldChild, int &exceptioncode ); virtual NodeImpl *appendChild ( NodeImpl *newChild, int &exceptioncode ); virtual NodeImpl *addChild( NodeImpl* newChild ); --- branches/KDE/3.5/kdelibs/khtml/html/html_tableimpl.cpp #583313:583314 @@ -389,21 +389,18 @@ return retval; } -NodeImpl *HTMLTableElementImpl::replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode ) +void HTMLTableElementImpl::replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode ) { handleChildRemove( oldChild ); //Always safe. - - NodeImpl* retval = HTMLElementImpl::replaceChild( newChild, oldChild, exceptioncode ); - if (retval) + HTMLElementImpl::replaceChild( newChild, oldChild, exceptioncode ); + if ( !exceptioncode ) handleChildAdd( newChild ); - - return retval; } -NodeImpl *HTMLTableElementImpl::removeChild ( NodeImpl *oldChild, int &exceptioncode ) +void HTMLTableElementImpl::removeChild ( NodeImpl *oldChild, int &exceptioncode ) { handleChildRemove( oldChild ); - return HTMLElementImpl::removeChild( oldChild, exceptioncode); + HTMLElementImpl::removeChild( oldChild, exceptioncode); } void HTMLTableElementImpl::parseAttribute(AttributeImpl *attr) --- branches/KDE/3.5/kdelibs/khtml/html/html_tableimpl.h #583313:583314 @@ -277,8 +277,8 @@ // overrides virtual NodeImpl *addChild(NodeImpl *child); virtual NodeImpl *insertBefore ( NodeImpl *newChild, NodeImpl *refChild, int &exceptioncode ); - virtual NodeImpl *replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode ); - virtual NodeImpl *removeChild ( NodeImpl *oldChild, int &exceptioncode ); + virtual void replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode ); + virtual void removeChild ( NodeImpl *oldChild, int &exceptioncode ); virtual NodeImpl *appendChild ( NodeImpl *newChild, int &exceptioncode ); virtual void parseAttribute(AttributeImpl *attr); --- branches/KDE/3.5/kdelibs/khtml/html/htmlparser.cpp #583313:583314 @@ -1408,6 +1408,7 @@ // The end result will be: ...FooGoo
// // Step 1: Remove |blockElem| from its parent, doing a batch detach of all the kids. + SharedPtr