Bug 877164, return early if nsDocument::Init fails, r=smaug

This commit is contained in:
gkrizsanits@mozilla.com 2013-07-27 12:12:38 +03:00
parent 071d2f1f08
commit 304cb6502e
2 changed files with 10 additions and 13 deletions

View File

@ -169,20 +169,19 @@ RemoveFromAgentSheets(nsCOMArray<nsIStyleSheet> &aAgentSheets, const nsAString&
nsresult nsresult
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData) NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData)
{ {
nsHTMLDocument* doc = new nsHTMLDocument(); nsRefPtr<nsHTMLDocument> doc = new nsHTMLDocument();
NS_ENSURE_TRUE(doc, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(doc);
nsresult rv = doc->Init(); nsresult rv = doc->Init();
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_RELEASE(doc); *aInstancePtrResult = nullptr;
return rv;
} }
*aInstancePtrResult = doc;
doc->SetLoadedAsData(aLoadedAsData); doc->SetLoadedAsData(aLoadedAsData);
doc.forget(aInstancePtrResult);
return rv; return NS_OK;
} }
// NOTE! nsDocument::operator new() zeroes out all members, so don't // NOTE! nsDocument::operator new() zeroes out all members, so don't

View File

@ -173,24 +173,22 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
return NS_OK; return NS_OK;
} }
nsresult nsresult
NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData) NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData)
{ {
XMLDocument* doc = new XMLDocument(); nsRefPtr<XMLDocument> doc = new XMLDocument();
NS_ENSURE_TRUE(doc, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(doc);
nsresult rv = doc->Init(); nsresult rv = doc->Init();
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_RELEASE(doc); *aInstancePtrResult = nullptr;
return rv;
} }
*aInstancePtrResult = doc;
doc->SetLoadedAsData(aLoadedAsData); doc->SetLoadedAsData(aLoadedAsData);
doc.forget(aInstancePtrResult);
return rv; return NS_OK;
} }
nsresult nsresult