Bug 1192230 - clean up reference-counting in xpcom/; r=erahm

This commit is contained in:
Nathan Froyd 2015-07-01 12:27:43 -04:00
Родитель 2654a75663
Коммит 3b0a318c70
11 изменённых файлов: 43 добавлений и 81 удалений

Просмотреть файл

@ -13,6 +13,7 @@
#include "nsCOMArray.h"
#include "nsCOMPtr.h"
#include "mozilla/nsRefPtr.h"
class nsSimpleArrayEnumerator final : public nsISimpleEnumerator
{
@ -91,12 +92,8 @@ nsSimpleArrayEnumerator::GetNext(nsISupports** aResult)
nsresult
NS_NewArrayEnumerator(nsISimpleEnumerator** aResult, nsIArray* aArray)
{
nsSimpleArrayEnumerator* enumer = new nsSimpleArrayEnumerator(aArray);
if (!enumer) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aResult = enumer);
nsRefPtr<nsSimpleArrayEnumerator> enumer = new nsSimpleArrayEnumerator(aArray);
enumer.forget(aResult);
return NS_OK;
}
@ -210,11 +207,7 @@ nsresult
NS_NewArrayEnumerator(nsISimpleEnumerator** aResult,
const nsCOMArray_base& aArray)
{
nsCOMArrayEnumerator* enumerator = new (aArray) nsCOMArrayEnumerator();
if (!enumerator) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aResult = enumerator);
nsRefPtr<nsCOMArrayEnumerator> enumerator = new (aArray) nsCOMArrayEnumerator();
enumerator.forget(aResult);
return NS_OK;
}

Просмотреть файл

@ -12,6 +12,7 @@
#include "nsIStringEnumerator.h"
#include "nsCOMPtr.h"
#include "mozilla/nsRefPtr.h"
class EmptyEnumeratorImpl
: public nsISimpleEnumerator
@ -163,12 +164,8 @@ nsresult
NS_NewSingletonEnumerator(nsISimpleEnumerator** aResult,
nsISupports* aSingleton)
{
nsSingletonEnumerator* enumer = new nsSingletonEnumerator(aSingleton);
if (!enumer) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aResult = enumer;
NS_ADDREF(*aResult);
nsRefPtr<nsSingletonEnumerator> enumer = new nsSingletonEnumerator(aSingleton);
enumer.forget(aResult);
return NS_OK;
}

Просмотреть файл

@ -348,8 +348,7 @@ nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
return rv;
}
*aLocalFile = localDir;
NS_ADDREF(*aLocalFile);
localDir.forget(aLocalFile);
return rv;
}
@ -395,8 +394,7 @@ nsAppFileLocationProvider::GetDefaultUserProfileRoot(nsIFile** aLocalFile,
}
#endif
*aLocalFile = localDir;
NS_ADDREF(*aLocalFile);
localDir.forget(aLocalFile);
return rv;
}

Просмотреть файл

@ -76,18 +76,16 @@ nsDirectoryService::GetCurrentProcessDirectory(nsIFile** aFile)
}
if (dirService) {
nsCOMPtr <nsIFile> aLocalFile;
nsCOMPtr<nsIFile> localFile;
dirService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile),
getter_AddRefs(aLocalFile));
if (aLocalFile) {
*aFile = aLocalFile;
NS_ADDREF(*aFile);
getter_AddRefs(localFile));
if (localFile) {
localFile.forget(aFile);
return NS_OK;
}
}
nsLocalFile* localFile = new nsLocalFile;
NS_ADDREF(localFile);
nsRefPtr<nsLocalFile> localFile = new nsLocalFile;
#ifdef XP_WIN
wchar_t buf[MAX_PATH + 1];
@ -101,7 +99,7 @@ nsDirectoryService::GetCurrentProcessDirectory(nsIFile** aFile)
}
localFile->InitWithPath(nsDependentString(buf));
*aFile = localFile;
localFile.forget(aFile);
return NS_OK;
}
@ -125,7 +123,7 @@ nsDirectoryService::GetCurrentProcessDirectory(nsIFile** aFile)
#endif
rv = localFile->InitWithNativePath(nsDependentCString(buffer));
if (NS_SUCCEEDED(rv)) {
*aFile = localFile;
localFile.forget(aFile);
}
}
CFRelease(parentURL);
@ -167,7 +165,7 @@ nsDirectoryService::GetCurrentProcessDirectory(nsIFile** aFile)
if (moz5 && *moz5) {
if (realpath(moz5, buf)) {
localFile->InitWithNativePath(nsDependentCString(buf));
*aFile = localFile;
localFile.forget(aFile);
return NS_OK;
}
}
@ -184,14 +182,12 @@ nsDirectoryService::GetCurrentProcessDirectory(nsIFile** aFile)
// Fall back to current directory.
if (getcwd(buf, sizeof(buf))) {
localFile->InitWithNativePath(nsDependentCString(buf));
*aFile = localFile;
localFile.forget(aFile);
return NS_OK;
}
#endif
NS_RELEASE(localFile);
NS_ERROR("unable to get current process directory");
return NS_ERROR_FAILURE;
} // GetCurrentProcessDirectory()

Просмотреть файл

@ -358,7 +358,7 @@ NS_NewInputStreamTeeAsync(nsIInputStream** aResult,
return rv;
}
NS_ADDREF(*aResult = tee);
tee.forget(aResult);
return rv;
}

Просмотреть файл

@ -1179,8 +1179,8 @@ NS_IMETHODIMP
nsLocalFile::Clone(nsIFile** aFile)
{
// Just copy-construct ourselves
*aFile = new nsLocalFile(*this);
NS_ADDREF(*aFile);
nsRefPtr<nsLocalFile> file = new nsLocalFile(*this);
file.forget(aFile);
return NS_OK;
}
@ -3214,14 +3214,12 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator** aEntries)
*aEntries = nullptr;
if (mWorkingPath.EqualsLiteral("\\\\.")) {
nsDriveEnumerator* drives = new nsDriveEnumerator;
NS_ADDREF(drives);
nsRefPtr<nsDriveEnumerator> drives = new nsDriveEnumerator;
rv = drives->Init();
if (NS_FAILED(rv)) {
NS_RELEASE(drives);
return rv;
}
*aEntries = drives;
drives.forget(aEntries);
return NS_OK;
}
@ -3360,20 +3358,18 @@ nsLocalFile::Launch()
nsresult
NS_NewLocalFile(const nsAString& aPath, bool aFollowLinks, nsIFile** aResult)
{
nsLocalFile* file = new nsLocalFile();
NS_ADDREF(file);
nsRefPtr<nsLocalFile> file = new nsLocalFile();
file->SetFollowLinks(aFollowLinks);
if (!aPath.IsEmpty()) {
nsresult rv = file->InitWithPath(aPath);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
return rv;
}
}
*aResult = file;
file.forget(aResult);
return NS_OK;
}

Просмотреть файл

@ -696,13 +696,9 @@ nsMultiplexInputStreamConstructor(nsISupports* aOuter,
return NS_ERROR_NO_AGGREGATION;
}
nsMultiplexInputStream* inst = new nsMultiplexInputStream();
nsRefPtr<nsMultiplexInputStream> inst = new nsMultiplexInputStream();
NS_ADDREF(inst);
nsresult rv = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
return rv;
return inst->QueryInterface(aIID, aResult);
}
void

Просмотреть файл

@ -129,9 +129,6 @@ nsScriptableInputStream::Create(nsISupports* aOuter, REFNSIID aIID,
return NS_ERROR_NO_AGGREGATION;
}
nsScriptableInputStream* sis = new nsScriptableInputStream();
NS_ADDREF(sis);
nsresult rv = sis->QueryInterface(aIID, aResult);
NS_RELEASE(sis);
return rv;
nsRefPtr<nsScriptableInputStream> sis = new nsScriptableInputStream();
return sis->QueryInterface(aIID, aResult);
}

Просмотреть файл

@ -400,17 +400,15 @@ nsStorageStream::NewInputStream(int32_t aStartingOffset,
return NS_ERROR_NOT_INITIALIZED;
}
nsStorageInputStream* inputStream =
nsRefPtr<nsStorageInputStream> inputStream =
new nsStorageInputStream(this, mSegmentSize);
NS_ADDREF(inputStream);
nsresult rv = inputStream->Seek(aStartingOffset);
if (NS_FAILED(rv)) {
NS_RELEASE(inputStream);
return rv;
}
*aInputStream = inputStream;
inputStream.forget(aInputStream);
return NS_OK;
}
@ -625,14 +623,12 @@ nsresult
NS_NewStorageStream(uint32_t aSegmentSize, uint32_t aMaxSize,
nsIStorageStream** aResult)
{
nsStorageStream* storageStream = new nsStorageStream();
NS_ADDREF(storageStream);
nsRefPtr<nsStorageStream> storageStream = new nsStorageStream();
nsresult rv = storageStream->Init(aSegmentSize, aMaxSize);
if (NS_FAILED(rv)) {
NS_RELEASE(storageStream);
return rv;
}
*aResult = storageStream;
storageStream.forget(aResult);
return NS_OK;
}

Просмотреть файл

@ -380,8 +380,7 @@ NS_NewByteInputStream(nsIInputStream** aStreamResult,
{
NS_PRECONDITION(aStreamResult, "null out ptr");
nsStringInputStream* stream = new nsStringInputStream();
NS_ADDREF(stream);
nsRefPtr<nsStringInputStream> stream = new nsStringInputStream();
nsresult rv;
switch (aAssignment) {
@ -400,11 +399,10 @@ NS_NewByteInputStream(nsIInputStream** aStreamResult,
}
if (NS_FAILED(rv)) {
NS_RELEASE(stream);
return rv;
}
*aStreamResult = stream;
stream.forget(aStreamResult);
return NS_OK;
}
@ -422,12 +420,11 @@ NS_NewCStringInputStream(nsIInputStream** aStreamResult,
{
NS_PRECONDITION(aStreamResult, "null out ptr");
nsStringInputStream* stream = new nsStringInputStream();
NS_ADDREF(stream);
nsRefPtr<nsStringInputStream> stream = new nsStringInputStream();
stream->SetData(aStringToRead);
*aStreamResult = stream;
stream.forget(aStreamResult);
return NS_OK;
}
@ -442,10 +439,6 @@ nsStringInputStreamConstructor(nsISupports* aOuter, REFNSIID aIID,
return NS_ERROR_NO_AGGREGATION;
}
nsStringInputStream* inst = new nsStringInputStream();
NS_ADDREF(inst);
nsresult rv = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
return rv;
nsRefPtr<nsStringInputStream> inst = new nsStringInputStream();
return inst->QueryInterface(aIID, aResult);
}

Просмотреть файл

@ -412,9 +412,9 @@ NS_IMETHODIMP
nsSimpleUnicharStreamFactory::CreateInstanceFromString(const nsAString& aString,
nsIUnicharInputStream** aResult)
{
StringUnicharInputStream* it = new StringUnicharInputStream(aString);
nsRefPtr<StringUnicharInputStream> it = new StringUnicharInputStream(aString);
NS_ADDREF(*aResult = it);
it.forget(aResult);
return NS_OK;
}
@ -432,7 +432,7 @@ nsSimpleUnicharStreamFactory::CreateInstanceFromUTF8Stream(
return rv;
}
NS_ADDREF(*aResult = it);
it.forget(aResult);
return NS_OK;
}