Bug 1428860 - XULDocument::GetElementsByAttributeNS may leak memory r?peterv
MozReview-Commit-ID: Kjsi1MfGIEs
--- 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,