[webkit-changes] cvs commit: WebCore/khtml/xml dom_nodeimpl.cpp

Darin darin at opensource.apple.com
Tue Sep 6 19:38:36 PDT 2005


darin       05/09/06 19:38:36

  Modified:    .        ChangeLog
               khtml/html html_elementimpl.cpp html_tableimpl.cpp
               khtml/xml dom_nodeimpl.cpp
  Log:
          Reviewed by John Sullivan.
  
          - fixed storage leaks; one of the leaks caused these 3 bugs:
  
          <rdar://problem/4231952> leaks of DOMStringImpl called from HTMLTokenizer::processToken, seen running WebKit tests
          <http://bugzilla.opendarwin.org/show_bug.cgi?id=4797>
  
          <rdar://problem/4233800> leak inside DOM::DocumentImpl::DocumentImpl, seen running webkit tests
          <http://bugzilla.opendarwin.org/show_bug.cgi?id=4795>
  
          <rdar://problem/4232812> leaks of NodeImpl called from HTMLParser::textCreateErrorCheck, seen running webkit tests
          <http://bugzilla.opendarwin.org/show_bug.cgi?id=4796>
  
          * khtml/html/html_elementimpl.cpp:
          (HTMLElementImpl::setOuterHTML): Put ref/deref around call to replaceChild to avoid leaking the node being replaced.
          (HTMLElementImpl::setOuterText): Put ref/deref around call to replaceChild to avoid leaking the node being replaced.
          Also changed removeChild calls to use remove instead, both for simplicity and to fix the leak without having
          to add a SharedPtr or ref/deref pair.
  
          * khtml/html/html_tableimpl.cpp:
          (DOM::HTMLTableElementImpl::setCaption): Put ref/deref around call to replaceChild to avoid leaking the node being
          replaced.
          (DOM::HTMLTableElementImpl::setTHead): Ditto.
          (DOM::HTMLTableElementImpl::setTFoot): Ditto.
          (DOM::HTMLTableElementImpl::setTBody): Tweaked a bit to match the other functions as closely as possible.
          No leak here.
  
          * khtml/xml/dom_nodeimpl.cpp:
          (DOM::NodeImpl::remove): Added ref/deref to avoid leaking the node being removed.
          (DOM::NodeImpl::normalize): Changed two calls to removeChild to calls to remove to prevent leaks.
  
  Revision  Changes    Path
  1.99      +44 -1     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.98
  retrieving revision 1.99
  diff -u -r1.98 -r1.99
  --- ChangeLog	6 Sep 2005 23:53:09 -0000	1.98
  +++ ChangeLog	7 Sep 2005 02:38:34 -0000	1.99
  @@ -1,3 +1,47 @@
  +2005-09-06  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by John Sullivan.
  +
  +        - fixed storage leaks; one of the leaks caused these 3 bugs:
  +
  +        <rdar://problem/4231952> leaks of DOMStringImpl called from HTMLTokenizer::processToken, seen running WebKit tests
  +        <http://bugzilla.opendarwin.org/show_bug.cgi?id=4797>
  +
  +        <rdar://problem/4233800> leak inside DOM::DocumentImpl::DocumentImpl, seen running webkit tests
  +        <http://bugzilla.opendarwin.org/show_bug.cgi?id=4795>
  +
  +        <rdar://problem/4232812> leaks of NodeImpl called from HTMLParser::textCreateErrorCheck, seen running webkit tests
  +        <http://bugzilla.opendarwin.org/show_bug.cgi?id=4796>
  +
  +        * khtml/html/html_elementimpl.cpp:
  +        (HTMLElementImpl::setOuterHTML): Put ref/deref around call to replaceChild to avoid leaking the node being replaced.
  +        (HTMLElementImpl::setOuterText): Put ref/deref around call to replaceChild to avoid leaking the node being replaced.
  +        Also changed removeChild calls to use remove instead, both for simplicity and to fix the leak without having
  +        to add a SharedPtr or ref/deref pair.
  +
  +        * khtml/html/html_tableimpl.cpp:
  +        (DOM::HTMLTableElementImpl::setCaption): Put ref/deref around call to replaceChild to avoid leaking the node being
  +        replaced.
  +        (DOM::HTMLTableElementImpl::setTHead): Ditto.
  +        (DOM::HTMLTableElementImpl::setTFoot): Ditto.
  +        (DOM::HTMLTableElementImpl::setTBody): Tweaked a bit to match the other functions as closely as possible.
  +        No leak here.
  +
  +        * khtml/xml/dom_nodeimpl.cpp:
  +        (DOM::NodeImpl::remove): Added ref/deref to avoid leaking the node being removed.
  +        (DOM::NodeImpl::normalize): Changed two calls to removeChild to calls to remove to prevent leaks.
  +
  +2005-09-05  Darin Adler  <darin at apple.com>
  +
  +        Earlier version reviewed by John Sullivan.
  +
  +        * khtml/xml/dom_nodeimpl.cpp: (DOM::NodeImpl::remove): Add a ref/deref pair so that
  +        this function will destroy a node if it has no references other than the tree.
  +
  +        * khtml/html/html_elementimpl.cpp: (HTMLElementImpl::setOuterText): Change code to
  +        call remove instead of removeChild, both for simplicity and to fix leak without having
  +        to add a SharedPtr or ref/deref pair.
  +
   2005-09-06  Justin Garcia  <justin.garcia at apple.com>
   
           Reviewed by harrison
  @@ -15,7 +59,6 @@
           Even though the startBlock (selection.start().node()->enclosingBlockFlowElement) is where manipulation 
           begins on a paste, it can be missing necessary style information.
   
  -
   2005-09-06  Eric Seidel  <eseidel at apple.com>
           Fix by Tobias Lidskog <tobiaslidskog at mac.com>
   
  
  
  
  1.105     +7 -7      WebCore/khtml/html/html_elementimpl.cpp
  
  Index: html_elementimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_elementimpl.cpp,v
  retrieving revision 1.104
  retrieving revision 1.105
  diff -u -r1.104 -r1.105
  --- html_elementimpl.cpp	3 Sep 2005 23:09:59 -0000	1.104
  +++ html_elementimpl.cpp	7 Sep 2005 02:38:35 -0000	1.105
  @@ -371,9 +371,9 @@
           return;
       }
       
  -    if (parentNode()) {
  -        parentNode()->replaceChild(fragment, this, exception);
  -    }
  +    ref();
  +    parent->replaceChild(fragment, this, exception);
  +    deref();
   }
   
   
  @@ -421,7 +421,9 @@
       }
   
       TextImpl *t = new TextImpl(docPtr(), text);
  +    ref();
       parent->replaceChild(t, this, exception);
  +    deref();
       if (exception)
           return;
   
  @@ -432,9 +434,7 @@
   	textPrev->appendData(t->data(), exception);
           if (exception)
               return;
  -        t->ref();
  -	t->parentNode()->removeChild(t, exception);
  -        t->deref();
  +        t->remove(exception);
           if (exception)
               return;
   	t = textPrev;
  @@ -447,7 +447,7 @@
   	t->appendData(textNext->data(), exception);
           if (exception)
               return;
  -	textNext->parentNode()->removeChild(textNext, exception);
  +        textNext->remove(exception);
           if (exception)
               return;
       }
  
  
  
  1.63      +28 -27    WebCore/khtml/html/html_tableimpl.cpp
  
  Index: html_tableimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_tableimpl.cpp,v
  retrieving revision 1.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- html_tableimpl.cpp	31 Aug 2005 15:36:12 -0000	1.62
  +++ html_tableimpl.cpp	7 Sep 2005 02:38:35 -0000	1.63
  @@ -88,13 +88,14 @@
   NodeImpl* HTMLTableElementImpl::setCaption( HTMLTableCaptionElementImpl *c )
   {
       int exceptioncode = 0;
  -    NodeImpl* r;
  -    if(tCaption) {
  -        replaceChild ( c, tCaption, exceptioncode );
  +    NodeImpl *r;
  +    if (NodeImpl *oc = tCaption) {
  +        oc->ref();
  +        replaceChild(c, oc, exceptioncode);
  +        oc->deref();
           r = c;
  -    }
  -    else
  -        r = insertBefore( c, firstChild(), exceptioncode );
  +    } else
  +        r = insertBefore(c, firstChild(), exceptioncode);
       tCaption = c;
       return r;
   }
  @@ -102,18 +103,18 @@
   NodeImpl* HTMLTableElementImpl::setTHead( HTMLTableSectionElementImpl *s )
   {
       int exceptioncode = 0;
  -    NodeImpl* r;
  -    if(head) {
  -        replaceChild( s, head, exceptioncode );
  +    NodeImpl *r;
  +    if (NodeImpl *h = head) {
  +        h->ref();
  +        replaceChild(s, h, exceptioncode);
  +        h->deref();
           r = s;
  -    }
  -    else if( foot )
  -        r = insertBefore( s, foot, exceptioncode );
  -    else if( firstBody )
  -        r = insertBefore( s, firstBody, exceptioncode );
  +    } else if (foot)
  +        r = insertBefore(s, foot, exceptioncode);
  +    else if (firstBody)
  +        r = insertBefore(s, firstBody, exceptioncode);
       else
  -        r = appendChild( s, exceptioncode );
  -
  +        r = appendChild(s, exceptioncode);
       head = s;
       return r;
   }
  @@ -122,13 +123,15 @@
   {
       int exceptioncode = 0;
       NodeImpl* r;
  -    if(foot) {
  -        replaceChild ( s, foot, exceptioncode );
  +    if (NodeImpl *f = foot) {
  +        f->ref();
  +        replaceChild(s, f, exceptioncode);
  +        f->deref();
           r = s;
  -    } else if( firstBody )
  -        r = insertBefore( s, firstBody, exceptioncode );
  +    } else if (firstBody)
  +        r = insertBefore(s, firstBody, exceptioncode);
       else
  -        r = appendChild( s, exceptioncode );
  +        r = appendChild(s, exceptioncode);
       foot = s;
       return r;
   }
  @@ -137,16 +140,14 @@
   {
       int exceptioncode = 0;
       NodeImpl* r;
  -
       s->ref();
  -    if(firstBody) {
  -        replaceChild ( s, firstBody, exceptioncode );
  -        firstBody->deref();
  +    if (NodeImpl *fb = firstBody) {
  +        replaceChild(s, fb, exceptioncode);
  +        fb->deref();
           r = s;
       } else
  -        r = appendChild( s, exceptioncode );
  +        r = appendChild(s, exceptioncode);
       firstBody = s;
  -
       return r;
   }
   
  
  
  
  1.185     +7 -8      WebCore/khtml/xml/dom_nodeimpl.cpp
  
  Index: dom_nodeimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_nodeimpl.cpp,v
  retrieving revision 1.184
  retrieving revision 1.185
  diff -u -r1.184 -r1.185
  --- dom_nodeimpl.cpp	4 Sep 2005 09:55:07 -0000	1.184
  +++ dom_nodeimpl.cpp	7 Sep 2005 02:38:35 -0000	1.185
  @@ -236,13 +236,12 @@
   
   void NodeImpl::remove(int &exceptioncode)
   {
  -    exceptioncode = 0;
  -    if (!parentNode()) {
  +    ref();
  +    if (NodeImpl *p = parentNode())
  +        p->removeChild(this, exceptioncode);
  +    else
           exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;
  -        return;
  -    }
  -    
  -    parentNode()->removeChild(this, exceptioncode);
  +    deref();
   }
   
   bool NodeImpl::hasChildNodes(  ) const
  @@ -287,7 +286,7 @@
               if (exceptioncode)
                   return;
   
  -            removeChild(nextChild,exceptioncode);
  +            nextChild->remove(exceptioncode);
               if (exceptioncode)
                   return;
           }
  @@ -302,7 +301,7 @@
       if (child && !child->nextSibling() && child->isTextNode()) {
           TextImpl *text = static_cast<TextImpl*>(child);
           if (text->data().isEmpty())
  -            removeChild(child, exceptioncode);
  +            child->remove(exceptioncode);
       }
   }
   
  
  
  



More information about the webkit-changes mailing list