Bug 1393642 (follow-up) - Fix potential leak in HTMLEditor methods. r=masayuki.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 07 Sep 2017 12:20:51 +1000
changeset 428900 cb6fcd43e5a505475df2c38a8475bc84d485975b
parent 428899 31ba8f169c5d1d4b118fdd7bd627a991544e7f5a
child 428901 93d2637ff309bbae9c09ef0eb085771d40ff7c66
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1393642
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1393642 (follow-up) - Fix potential leak in HTMLEditor methods. r=masayuki. As written, these functions will leak if they are passed strings that don't match static atoms. In practice, all strings passed *do* match static atoms, but let's fix it anyway in case that changes in the future.
editor/libeditor/HTMLStyleEditor.cpp
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -54,17 +54,18 @@ IsEmptyTextNode(HTMLEditor* aThis, nsINo
          isEmptyTextNode;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SetInlineProperty(const nsAString& aProperty,
                               const nsAString& aAttribute,
                               const nsAString& aValue)
 {
-  return SetInlineProperty(NS_Atomize(aProperty).take(), aAttribute, aValue);
+  nsCOMPtr<nsIAtom> property = NS_Atomize(aProperty);
+  return SetInlineProperty(property, aAttribute, aValue);
 }
 
 nsresult
 HTMLEditor::SetInlineProperty(nsIAtom* aProperty,
                               const nsAString& aAttribute,
                               const nsAString& aValue)
 {
   NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);
@@ -1073,18 +1074,18 @@ HTMLEditor::GetInlinePropertyBase(nsIAto
 NS_IMETHODIMP
 HTMLEditor::GetInlineProperty(const nsAString& aProperty,
                               const nsAString& aAttribute,
                               const nsAString& aValue,
                               bool* aFirst,
                               bool* aAny,
                               bool* aAll)
 {
-  return GetInlineProperty(NS_Atomize(aProperty).take(), aAttribute, aValue,
-                           aFirst, aAny, aAll);
+  nsCOMPtr<nsIAtom> property = NS_Atomize(aProperty);
+  return GetInlineProperty(property, aAttribute, aValue, aFirst, aAny, aAll);
 }
 
 nsresult
 HTMLEditor::GetInlineProperty(nsIAtom* aProperty,
                               const nsAString& aAttribute,
                               const nsAString& aValue,
                               bool* aFirst,
                               bool* aAny,
@@ -1104,19 +1105,19 @@ NS_IMETHODIMP
 HTMLEditor::GetInlinePropertyWithAttrValue(const nsAString& aProperty,
                                            const nsAString& aAttribute,
                                            const nsAString& aValue,
                                            bool* aFirst,
                                            bool* aAny,
                                            bool* aAll,
                                            nsAString& outValue)
 {
-  return GetInlinePropertyWithAttrValue(NS_Atomize(aProperty).take(),
-                                        aAttribute, aValue, aFirst, aAny,
-                                        aAll, outValue);
+  nsCOMPtr<nsIAtom> property = NS_Atomize(aProperty);
+  return GetInlinePropertyWithAttrValue(property, aAttribute, aValue, aFirst,
+                                        aAny, aAll, outValue);
 }
 
 nsresult
 HTMLEditor::GetInlinePropertyWithAttrValue(nsIAtom* aProperty,
                                            const nsAString& aAttribute,
                                            const nsAString& aValue,
                                            bool* aFirst,
                                            bool* aAny,
@@ -1144,17 +1145,18 @@ HTMLEditor::RemoveAllInlineProperties()
   NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::RemoveInlineProperty(const nsAString& aProperty,
                                  const nsAString& aAttribute)
 {
-  return RemoveInlineProperty(NS_Atomize(aProperty).take(), aAttribute);
+  nsCOMPtr<nsIAtom> property = NS_Atomize(aProperty);
+  return RemoveInlineProperty(property, aAttribute);
 }
 
 nsresult
 HTMLEditor::RemoveInlineProperty(nsIAtom* aProperty,
                                  const nsAString& aAttribute)
 {
   return RemoveInlinePropertyImpl(aProperty, &aAttribute);
 }