Bug 1153267 - part 2 - use smart pointers instead of manual NS_ADDREF'ing outparams; r=ehsan

This commit is contained in:
Nathan Froyd 2015-03-31 10:05:07 -04:00
parent 2b1ae6e2ca
commit dbc40671bc
5 changed files with 16 additions and 28 deletions

View File

@ -1214,15 +1214,13 @@ nsJSProtocolHandler::NewChannel2(nsIURI* uri,
nsIChannel** result)
{
nsresult rv;
nsJSChannel * channel;
NS_ENSURE_ARG_POINTER(uri);
channel = new nsJSChannel();
nsRefPtr<nsJSChannel> channel = new nsJSChannel();
if (!channel) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(channel);
rv = channel->Init(uri);
@ -1231,10 +1229,8 @@ nsJSProtocolHandler::NewChannel2(nsIURI* uri,
NS_ENSURE_SUCCESS(rv, rv);
if (NS_SUCCEEDED(rv)) {
*result = channel;
NS_ADDREF(*result);
channel.forget(result);
}
NS_RELEASE(channel);
return rv;
}

View File

@ -90,19 +90,16 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULPrototypeDocument)
NS_IMETHODIMP
NS_NewXULPrototypeDocument(nsXULPrototypeDocument** aResult)
{
*aResult = new nsXULPrototypeDocument();
if (! *aResult)
return NS_ERROR_OUT_OF_MEMORY;
*aResult = nullptr;
nsRefPtr<nsXULPrototypeDocument> doc =
new nsXULPrototypeDocument();
nsresult rv;
rv = (*aResult)->Init();
nsresult rv = doc->Init();
if (NS_FAILED(rv)) {
delete *aResult;
*aResult = nullptr;
return rv;
}
NS_ADDREF(*aResult);
doc.forget(aResult);
return rv;
}

View File

@ -583,12 +583,11 @@ nsXULTemplateQueryProcessorRDF::TranslateRef(nsISupports* aDatasource,
nsCOMPtr<nsIRDFResource> uri;
gRDFService->GetUnicodeResource(aRefString, getter_AddRefs(uri));
nsXULTemplateResultRDF* refresult = new nsXULTemplateResultRDF(uri);
nsRefPtr<nsXULTemplateResultRDF> refresult = new nsXULTemplateResultRDF(uri);
if (! refresult)
return NS_ERROR_OUT_OF_MEMORY;
*aRef = refresult;
NS_ADDREF(*aRef);
refresult.forget(aRef);
return NS_OK;
}

View File

@ -326,12 +326,11 @@ nsXULTemplateQueryProcessorXML::GenerateResults(nsISupports* aDatasource,
return rv.ErrorCode();
}
nsXULTemplateResultSetXML* results =
nsRefPtr<nsXULTemplateResultSetXML> results =
new nsXULTemplateResultSetXML(xmlquery, exprresults.forget(),
xmlquery->GetBindingSet());
*aResults = results;
NS_ADDREF(*aResults);
results.forget(aResults);
return NS_OK;
}
@ -385,8 +384,8 @@ nsXULTemplateQueryProcessorXML::TranslateRef(nsISupports* aDatasource,
if (!rootElement)
return NS_OK;
*aRef = new nsXULTemplateResultXML(nullptr, rootElement, nullptr);
NS_ADDREF(*aRef);
nsRefPtr<nsXULTemplateResultXML> result = new nsXULTemplateResultXML(nullptr, rootElement, nullptr);
result.forget(aRef);
return NS_OK;
}

View File

@ -170,19 +170,16 @@ nsDirectoryIndexStream::~nsDirectoryIndexStream()
nsresult
nsDirectoryIndexStream::Create(nsIFile* aDir, nsIInputStream** aResult)
{
nsDirectoryIndexStream* result = new nsDirectoryIndexStream();
nsRefPtr<nsDirectoryIndexStream> result = new nsDirectoryIndexStream();
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
rv = result->Init(aDir);
nsresult rv = result->Init(aDir);
if (NS_FAILED(rv)) {
delete result;
return rv;
}
*aResult = result;
NS_ADDREF(*aResult);
result.forget(aResult);
return NS_OK;
}