Bug 1428860 - XULDocument::GetElementsByAttributeNS may leak memory r?peterv
MozReview-Commit-ID: 5NjViIoivG1
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -1068,52 +1068,52 @@ XULDocument::ResolveForwardReferences()
// nsIDOMDocument interface
//
already_AddRefed<nsINodeList>
XULDocument::GetElementsByAttribute(const nsAString& aAttribute,
const nsAString& aValue)
{
RefPtr<nsAtom> attrAtom(NS_Atomize(aAttribute));
- void* attrValue = new nsString(aValue);
+ nsAutoPtr<nsString> attrValue(new nsString(aValue));
RefPtr<nsContentList> list = new nsContentList(this,
MatchAttribute,
nsContentUtils::DestroyMatchString,
- attrValue,
+ attrValue.forget(),
true,
attrAtom,
kNameSpaceID_Unknown);
return list.forget();
}
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();
}
void
XULDocument::Persist(const nsAString& aID,