Bug 1428860 - XULDocument::GetElementsByAttributeNS may leak memory r?peterv draft
authorJean-Luc Bonnafoux <jeanluc.bonnafoux@wanadoo.fr>
Wed, 21 Feb 2018 21:34:39 +0100
changeset 758045 e29ca281336d02f6760d39812d99be7da284e7c2
parent 750267 854eb93a6c53ceef1c3f322ea77bb965cf69bd1d
child 759512 07ca950e7175e9ecfaa0855f4878963904b1a5d6
push id99933
push userbmo:jeanluc.bonnafoux@wanadoo.fr
push dateWed, 21 Feb 2018 20:48:27 +0000
reviewerspeterv
bugs1428860
milestone59.0a1
Bug 1428860 - XULDocument::GetElementsByAttributeNS may leak memory r?peterv MozReview-Commit-ID: Kjsi1MfGIEs
dom/xul/XULDocument.cpp
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -1111,21 +1111,21 @@ XULDocument::GetElementsByAttribute(cons
     return NS_OK;
 }
 
 already_AddRefed<nsINodeList>
 XULDocument::GetElementsByAttribute(const nsAString& aAttribute,
                                     const nsAString& aValue)
 {
     RefPtr<nsAtom> attrAtom(NS_Atomize(aAttribute));
-    nsAutoPtr<nsString> attrValue = new nsString(aValue);
+    nsAutoPtr<nsString> attrValue(new nsString(aValue));
     RefPtr<nsContentList> list = new nsContentList(this,
                                             MatchAttribute,
                                             nsContentUtils::DestroyMatchString,
-                                            reinterpret_cast<void*>(attrValue.forget()),
+                                            attrValue.forget(),
                                             true,
                                             attrAtom,
                                             kNameSpaceID_Unknown);
 
     return list.forget();
 }
 
 NS_IMETHODIMP
@@ -1142,33 +1142,33 @@ XULDocument::GetElementsByAttributeNS(co
 
 already_AddRefed<nsINodeList>
 XULDocument::GetElementsByAttributeNS(const nsAString& aNamespaceURI,
                                       const nsAString& aAttribute,
                                       const nsAString& aValue,
                                       ErrorResult& aRv)
 {
     RefPtr<nsAtom> attrAtom(NS_Atomize(aAttribute));
-    void* attrValue = new nsString(aValue);
+    nsAutoPtr<nsString> attrValue(new nsString(aValue));
 
     int32_t nameSpaceId = kNameSpaceID_Wildcard;
     if (!aNamespaceURI.EqualsLiteral("*")) {
       nsresult rv =
         nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURI,
                                                               nameSpaceId);
       if (NS_FAILED(rv)) {
           aRv.Throw(rv);
           return nullptr;
       }
     }
 
     RefPtr<nsContentList> list = new nsContentList(this,
                                             MatchAttribute,
                                             nsContentUtils::DestroyMatchString,
-                                            attrValue,
+                                            attrValue.forget(),
                                             true,
                                             attrAtom,
                                             nameSpaceId);
     return list.forget();
 }
 
 NS_IMETHODIMP
 XULDocument::Persist(const nsAString& aID,