Reviewed by Harrison
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Nov 2004 19:58:31 +0000 (19:58 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Nov 2004 19:58:31 +0000 (19:58 +0000)
        Fix some object lifetime issues in these two commands. This fixes some crashes
        I am seeing in some new code I am working on, but have not yet reproduced otherwise.

        * khtml/editing/htmlediting.cpp:
        (khtml::InsertParagraphSeparatorCommand::~InsertParagraphSeparatorCommand): No longer deref nodes
        in the ancestor list. They are not ref'ed when put on list. D'uh.
        (khtml::InsertParagraphSeparatorCommand::doApply): Ref all cloned nodes that are created by the command
        before putting them on the cloned nodes list. This are still deref'ed in the destructor.
        (khtml::InsertParagraphSeparatorInQuotedContentCommand::~InsertParagraphSeparatorInQuotedContentCommand): Ditto
        destructor comment.
        (khtml::InsertParagraphSeparatorInQuotedContentCommand::doApply): Ditto doApply comment.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8048 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp

index 4e49d184c3bdeb6dc2155b764b29a4b2bfd89257..f7bc857c8659113a46d07cf70bbe206b161c0bfa 100644 (file)
@@ -1,3 +1,19 @@
+2004-11-19  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Harrison
+
+        Fix some object lifetime issues in these two commands. This fixes some crashes
+        I am seeing in some new code I am working on, but have not yet reproduced otherwise.
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::InsertParagraphSeparatorCommand::~InsertParagraphSeparatorCommand): No longer deref nodes
+        in the ancestor list. They are not ref'ed when put on list. D'uh.
+        (khtml::InsertParagraphSeparatorCommand::doApply): Ref all cloned nodes that are created by the command
+        before putting them on the cloned nodes list. This are still deref'ed in the destructor.
+        (khtml::InsertParagraphSeparatorInQuotedContentCommand::~InsertParagraphSeparatorInQuotedContentCommand): Ditto
+        destructor comment.
+        (khtml::InsertParagraphSeparatorInQuotedContentCommand::doApply): Ditto doApply comment.
+
 2004-11-19  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by Harrison
index db603c2d269324cacdf13f421632e5e4a65f3908..8f0fb0d59c579546dc376ab71c6456f73a479e8b 100644 (file)
@@ -2118,7 +2118,6 @@ InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand(DocumentImpl *d
 
 InsertParagraphSeparatorCommand::~InsertParagraphSeparatorCommand() 
 {
-    derefNodesInList(ancestors);
     derefNodesInList(clonedNodes);
 }
 
@@ -2171,6 +2170,7 @@ void InsertParagraphSeparatorCommand::doApply()
         addedBlock = startBlock->cloneNode(false);
         insertNodeAfter(addedBlock, startBlock);
     }
+    addedBlock->ref();
     clonedNodes.append(addedBlock);
 
     if (!isLastVisiblePositionInNode(VisiblePosition(pos), startBlock)) {
@@ -2199,6 +2199,7 @@ void InsertParagraphSeparatorCommand::doApply()
         NodeImpl *parent = addedBlock;
         for (QPtrListIterator<NodeImpl> it(ancestors); it.current(); ++it) {
             NodeImpl *child = it.current()->cloneNode(false); // shallow clone
+            child->ref();
             clonedNodes.append(child);
             appendNode(child, parent);
             parent = child;
@@ -2244,7 +2245,6 @@ InsertParagraphSeparatorInQuotedContentCommand::InsertParagraphSeparatorInQuoted
 
 InsertParagraphSeparatorInQuotedContentCommand::~InsertParagraphSeparatorInQuotedContentCommand()
 {
-    derefNodesInList(ancestors);
     derefNodesInList(clonedNodes);
     if (m_breakNode)
         m_breakNode->deref();
@@ -2316,6 +2316,7 @@ void InsertParagraphSeparatorInQuotedContentCommand::doApply()
 
         // Insert a clone of the top blockquote after the break.
         NodeImpl *clonedBlockquote = topBlockquote->cloneNode(false);
+        clonedBlockquote->ref();
         clonedNodes.append(clonedBlockquote);
         insertNodeAfter(clonedBlockquote, m_breakNode);
         
@@ -2323,6 +2324,7 @@ void InsertParagraphSeparatorInQuotedContentCommand::doApply()
         NodeImpl *parent = clonedBlockquote;
         for (QPtrListIterator<NodeImpl> it(ancestors); it.current(); ++it) {
             NodeImpl *child = it.current()->cloneNode(false); // shallow clone
+            child->ref();
             clonedNodes.append(child);
             appendNode(child, parent);
             parent = child;
@@ -2347,6 +2349,7 @@ void InsertParagraphSeparatorInQuotedContentCommand::doApply()
             if (!leftParent)
                 leftParent = topBlockquote;
             ElementImpl *b = document()->createHTMLElement("BR", exceptionCode);
+            b->ref();
             clonedNodes.append(b);
             ASSERT(exceptionCode == 0);
             appendNode(b, leftParent);