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 118708 994fd11aab7a16422c4eeb7f258f72b0529af93a
parent 118707 8c226d1055443e0386b786c58caeb81f3d499fe1
child 118709 d1da79f1bf3691befeb38b5314261eae68470452
push id2900
push useropettay@mozilla.com
push dateSat, 08 Dec 2012 19:18:07 +0000
treeherdermozilla-aurora@994fd11aab7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, lsblakk
bugs803853
milestone19.0a2
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);
@@ -308,16 +312,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)