Bug 803853, make sure to not leak mRules, r=ehsan a=lsblakk
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Sat, 08 Dec 2012 21:16:29 +0200
changeset 117497 ac23834ccee4ae1f323cebc6e3f1695ae7ff55af
parent 117496 53c6251855680b76f62dee579ba08e2667827021
child 117498 39049b3abdd3312a7376deb99d6d66c8a11dc727
push id1919
push usereakhgari@mozilla.com
push dateWed, 12 Dec 2012 00:48:26 +0000
treeherdermozilla-beta@ac23834ccee4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, lsblakk
bugs803853
milestone18.0
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
@@ -267,16 +267,19 @@ nsHTMLEditRules::Init(nsPlaintextEditor 
   res = mHTMLEditor->AddEditActionListener(this);
 
   return res;
 }
 
 NS_IMETHODIMP
 nsHTMLEditRules::DetachEditor()
 {
+  if (mHTMLEditor) {
+    mHTMLEditor->RemoveEditActionListener(this);
+  }
   mHTMLEditor = nullptr;
   return nsTextEditRules::DetachEditor();
 }
 
 NS_IMETHODIMP
 nsHTMLEditRules::BeforeEdit(EditAction action,
                             nsIEditor::EDirection aDirection)
 {
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -479,16 +479,17 @@ nsHTMLEditor::SetFlags(uint32_t 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
@@ -116,16 +116,20 @@ NS_IMETHODIMP nsPlaintextEditor::Init(ns
                                       nsIContent *aRoot,
                                       nsISelectionController *aSelCon,
                                       uint32_t aFlags)
 {
   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 = nullptr;
+  }
   
   if (1)
   {
     // block to scope nsAutoEditInitRulesTrigger
     nsAutoEditInitRulesTrigger rulesTrigger(this, rulesRes);
   
     // Init the base editor
     res = nsEditor::Init(aDoc, aRoot, aSelCon, aFlags);
@@ -306,16 +310,17 @@ nsPlaintextEditor::UpdateMetaCharset(nsI
                                   NS_ConvertASCIItoUTF16(aCharacterSet));
     return NS_SUCCEEDED(rv);
   }
   return false;
 }
 
 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)