Bug 803853, make sure to not leak mRules, r=ehsan a=lsblakk
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Sat, 15 Dec 2012 03:34:16 +0200
changeset 82102 453fe2d875f6d25b4f449079255c016371e112a2
parent 82101 b894c9c7239ddeae7eaa861562fda910f3918e84
child 82103 f5ea6386c682d91063683346a945fefe7fd0e538
push id353
push useropettay@mozilla.com
push dateSat, 15 Dec 2012 01:58:12 +0000
reviewersehsan, lsblakk
bugs803853
milestone10.0.11esrpre
Bug 803853, make sure to not leak mRules, r=ehsan a=lsblakk
editor/libeditor/html/nsHTMLEditRules.cpp
editor/libeditor/html/nsHTMLEditor.cpp
editor/libeditor/text/nsPlaintextEditor.cpp
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -276,16 +276,19 @@ nsHTMLEditRules::Init(nsPlaintextEditor 
   res = mHTMLEditor->AddEditActionListener(this);
 
   return res;
 }
 
 NS_IMETHODIMP
 nsHTMLEditRules::DetachEditor()
 {
+  if (mHTMLEditor) {
+    mHTMLEditor->RemoveEditActionListener(this);
+  }
   mHTMLEditor = nsnull;
   return nsTextEditRules::DetachEditor();
 }
 
 NS_IMETHODIMP
 nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)
 {
   if (mLockRulesSniffing) return NS_OK;
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -518,16 +518,17 @@ nsHTMLEditor::SetFlags(PRUint32 aFlags)
   mCSSAware = !NoCSS() && !IsMailEditor();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::InitRules()
 {
+  MOZ_ASSERT(!mRules);
   // instantiate the rules for the html editor
   mRules = new nsHTMLEditRules();
   return mRules->Init(static_cast<nsPlaintextEditor*>(this));
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::BeginningOfDocument()
 {
--- a/editor/libeditor/text/nsPlaintextEditor.cpp
+++ b/editor/libeditor/text/nsPlaintextEditor.cpp
@@ -139,16 +139,20 @@ NS_IMETHODIMP nsPlaintextEditor::Init(ns
                                       PRUint32 aFlags)
 {
   NS_TIME_FUNCTION;
 
   NS_PRECONDITION(aDoc, "bad arg");
   NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER);
   
   nsresult res = NS_OK, rulesRes = NS_OK;
+  if (mRules) {
+    mRules->DetachEditor();
+    mRules = nsnull;
+  }
   
   if (1)
   {
     // block to scope nsAutoEditInitRulesTrigger
     nsAutoEditInitRulesTrigger rulesTrigger(this, rulesRes);
   
     // Init the base editor
     res = nsEditor::Init(aDoc, aRoot, aSelCon, aFlags);
@@ -317,16 +321,17 @@ nsPlaintextEditor::SetDocumentCharacterS
   } 
 
   return result; 
 } 
 
 
 NS_IMETHODIMP nsPlaintextEditor::InitRules()
 {
+  MOZ_ASSERT(!mRules);
   // instantiate the rules for this text editor
   mRules = new nsTextEditRules();
   return mRules->Init(this);
 }
 
 
 NS_IMETHODIMP
 nsPlaintextEditor::GetIsDocumentEditable(bool *aIsDocumentEditable)