Bug 1358979 - nsDocumentEncoder with RequiresReinitAfterOutput should reset some strong pointers. r?smaug draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 24 Apr 2017 18:14:53 +0900
changeset 567043 234b0057582206f65922e22bfeb9b514aaebd888
parent 566789 8e969cc9aff49f845678cba5b35d9dd8aa340f16
child 567044 af7402b354203a984428d3b392cd771cb04bad40
push id55426
push userm_kato@ga2.so-net.ne.jp
push dateMon, 24 Apr 2017 10:31:08 +0000
reviewerssmaug
bugs1358979
milestone55.0a1
Bug 1358979 - nsDocumentEncoder with RequiresReinitAfterOutput should reset some strong pointers. r?smaug We should release strong pointers into nsDocumentEncoder with RequiresReinitAfterOutput option to avoid holding dom node. Also, mStream and mUnicodeEncoder will release into EncodeToStream, so it is unnecessary to clear it. MozReview-Commit-ID: Ll8jFmMj4Ps
dom/base/nsDocumentEncoder.cpp
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -137,28 +137,30 @@ protected:
           return false;
       }
     }
     return true;
   }
 
   virtual bool IncludeInContext(nsINode *aNode);
 
+  void Clear();
+
   class MOZ_STACK_CLASS AutoReleaseDocumentIfNeeded final
   {
   public:
     explicit AutoReleaseDocumentIfNeeded(nsDocumentEncoder* aEncoder)
       : mEncoder(aEncoder)
     {
     }
 
     ~AutoReleaseDocumentIfNeeded()
     {
       if (mEncoder->mFlags & RequiresReinitAfterOutput) {
-        mEncoder->mDocument = nullptr;
+        mEncoder->Clear();
       }
     }
 
   private:
     nsDocumentEncoder* mEncoder;
   };
 
   nsCOMPtr<nsIDocument>          mDocument;
@@ -1010,16 +1012,29 @@ nsDocumentEncoder::SerializeRangeToStrin
     NS_ENSURE_SUCCESS(rv, rv);
   }
   rv = SerializeRangeContextEnd(mCommonAncestors, aOutputString);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return rv;
 }
 
+void
+nsDocumentEncoder::Clear()
+{
+  mDocument = nullptr;
+  mSelection = nullptr;
+  mRange = nullptr;
+  mNode = nullptr;
+  mCommonParent = nullptr;
+  mNodeFixup = nullptr;
+
+  Initialize(false);
+}
+
 NS_IMETHODIMP
 nsDocumentEncoder::EncodeToString(nsAString& aOutputString)
 {
   return EncodeToStringWithMaxLength(0, aOutputString);
 }
 
 NS_IMETHODIMP
 nsDocumentEncoder::EncodeToStringWithMaxLength(uint32_t aMaxLength,