Bug 901976 - don't null-check |new X| in xpcom/; r=bsmedberg

This commit is contained in:
Nathan Froyd 2013-08-05 11:16:53 -04:00
parent 8a9ab9e177
commit 5f9e07125e
9 changed files with 33 additions and 107 deletions

View File

@ -5,6 +5,7 @@
#include "nsErrorService.h"
#include "nsCRT.h"
#include "nsAutoPtr.h"
static void*
CloneCString(nsHashKey *aKey, void *aData, void* closure)
@ -65,13 +66,8 @@ nsresult
nsErrorService::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
NS_ENSURE_NO_AGGREGATION(outer);
nsErrorService* serv = new nsErrorService();
if (serv == nullptr)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(serv);
nsresult rv = serv->QueryInterface(aIID, aInstancePtr);
NS_RELEASE(serv);
return rv;
nsRefPtr<nsErrorService> serv = new nsErrorService();
return serv->QueryInterface(aIID, aInstancePtr);
}
NS_IMETHODIMP

View File

@ -554,11 +554,6 @@ RegisterStaticAtoms(const nsStaticAtom* aAtoms, uint32_t aAtomCount)
if (!gStaticAtomTable && !gStaticAtomTableSealed) {
gStaticAtomTable = new nsDataHashtable<nsStringHashKey, nsIAtom*>();
if (!gStaticAtomTable) {
delete gStaticAtomTable;
gStaticAtomTable = nullptr;
return NS_ERROR_OUT_OF_MEMORY;
}
gStaticAtomTable->Init();
}

View File

@ -6,6 +6,7 @@
#include "nsByteBuffer.h"
#include "nsIInputStream.h"
#include "nsCRT.h"
#include "nsAutoPtr.h"
#define MIN_BUFFER_SIZE 32
@ -23,7 +24,7 @@ ByteBufferImpl::Init(uint32_t aBufferSize)
mSpace = aBufferSize;
mLength = 0;
mBuffer = new char[aBufferSize];
return mBuffer ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMPL_ISUPPORTS1(ByteBufferImpl,nsIByteBuffer)
@ -43,14 +44,9 @@ ByteBufferImpl::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
ByteBufferImpl* it = new ByteBufferImpl();
if (nullptr == it)
return NS_ERROR_OUT_OF_MEMORY;
nsRefPtr<ByteBufferImpl> it = new ByteBufferImpl();
NS_ADDREF(it);
nsresult rv = it->QueryInterface(aIID, (void**)aResult);
NS_RELEASE(it);
return rv;
return it->QueryInterface(aIID, (void**)aResult);
}
NS_IMETHODIMP_(uint32_t)
@ -78,15 +74,12 @@ ByteBufferImpl::Grow(uint32_t aNewSize)
aNewSize = MIN_BUFFER_SIZE;
}
char* newbuf = new char[aNewSize];
if (nullptr != newbuf) {
if (0 != mLength) {
memcpy(newbuf, mBuffer, mLength);
}
delete[] mBuffer;
mBuffer = newbuf;
return true;
if (0 != mLength) {
memcpy(newbuf, mBuffer, mLength);
}
return false;
delete[] mBuffer;
mBuffer = newbuf;
return true;
}
NS_IMETHODIMP_(int32_t)

View File

@ -109,9 +109,6 @@ nsCheapSet<EntryType>::Put(const KeyType aVal)
case ONE:
{
nsTHashtable<EntryType> *table = new nsTHashtable<EntryType>();
if (!table) {
return NS_ERROR_OUT_OF_MEMORY;
}
table->Init();
EntryType *entry = GetSingleEntry();
table->PutEntry(entry->GetKey());

View File

@ -16,19 +16,14 @@
nsresult
NS_NewHashPropertyBag(nsIWritablePropertyBag* *_retval)
{
nsHashPropertyBag *hpb = new nsHashPropertyBag();
if (!hpb)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(hpb);
nsRefPtr<nsHashPropertyBag> hpb = new nsHashPropertyBag();
nsresult rv = hpb->Init();
if (NS_FAILED(rv)) {
NS_RELEASE(hpb);
return rv;
}
*_retval = hpb;
hpb.forget(_retval);
return NS_OK;
}
@ -182,8 +177,6 @@ NS_IMETHODIMP \
nsHashPropertyBag::SetPropertyAs ## Name (const nsAString & prop, Type value) \
{ \
nsCOMPtr<nsIWritableVariant> var = new nsVariant(); \
if (!var) \
return NS_ERROR_OUT_OF_MEMORY; \
var->SetAs ## Name(value); \
return SetProperty(prop, var); \
}
@ -247,8 +240,6 @@ NS_IMETHODIMP
nsHashPropertyBag::SetPropertyAsAString(const nsAString & prop, const nsAString & value)
{
nsCOMPtr<nsIWritableVariant> var = new nsVariant();
if (!var)
return NS_ERROR_OUT_OF_MEMORY;
var->SetAsAString(value);
return SetProperty(prop, var);
}
@ -257,8 +248,6 @@ NS_IMETHODIMP
nsHashPropertyBag::SetPropertyAsACString(const nsAString & prop, const nsACString & value)
{
nsCOMPtr<nsIWritableVariant> var = new nsVariant();
if (!var)
return NS_ERROR_OUT_OF_MEMORY;
var->SetAsACString(value);
return SetProperty(prop, var);
}
@ -267,8 +256,6 @@ NS_IMETHODIMP
nsHashPropertyBag::SetPropertyAsAUTF8String(const nsAString & prop, const nsACString & value)
{
nsCOMPtr<nsIWritableVariant> var = new nsVariant();
if (!var)
return NS_ERROR_OUT_OF_MEMORY;
var->SetAsAUTF8String(value);
return SetProperty(prop, var);
}
@ -277,8 +264,6 @@ NS_IMETHODIMP
nsHashPropertyBag::SetPropertyAsInterface(const nsAString & prop, nsISupports* value)
{
nsCOMPtr<nsIWritableVariant> var = new nsVariant();
if (!var)
return NS_ERROR_OUT_OF_MEMORY;
var->SetAsISupports(value);
return SetProperty(prop, var);
}

View File

@ -56,10 +56,7 @@ nsresult
nsObserverList::GetObserverList(nsISimpleEnumerator** anEnumerator)
{
nsRefPtr<nsObserverEnumerator> e(new nsObserverEnumerator(this));
if (!e)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*anEnumerator = e);
e.forget(anEnumerator);
return NS_OK;
}

View File

@ -5,6 +5,7 @@
#include "nsUnicharBuffer.h"
#include "nsCRT.h"
#include "nsAutoPtr.h"
#define MIN_BUFFER_SIZE 32
@ -19,14 +20,9 @@ UnicharBufferImpl::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
UnicharBufferImpl* it = new UnicharBufferImpl();
if (it == nullptr)
return NS_ERROR_OUT_OF_MEMORY;
nsRefPtr<UnicharBufferImpl> it = new UnicharBufferImpl();
NS_ADDREF(it);
nsresult rv = it->QueryInterface(aIID, aResult);
NS_RELEASE(it);
return rv;
return it->QueryInterface(aIID, aResult);
}
NS_IMETHODIMP
@ -38,7 +34,7 @@ UnicharBufferImpl::Init(uint32_t aBufferSize)
mSpace = aBufferSize;
mLength = 0;
mBuffer = new PRUnichar[aBufferSize];
return mBuffer ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMPL_ISUPPORTS1(UnicharBufferImpl, nsIUnicharBuffer)

View File

@ -11,6 +11,7 @@
#include "nsString.h"
#include "nsCOMPtr.h"
#include "mozilla/Attributes.h"
#include "nsAutoPtr.h"
//-----------------------------------------------------------------------------
@ -105,8 +106,6 @@ nsWindowsRegKey::OpenChild(const nsAString &path, uint32_t mode,
NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIWindowsRegKey> child = new nsWindowsRegKey();
if (!child)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = child->Open((uintptr_t) mKey, path, mode);
if (NS_FAILED(rv))
@ -123,8 +122,6 @@ nsWindowsRegKey::CreateChild(const nsAString &path, uint32_t mode,
NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIWindowsRegKey> child = new nsWindowsRegKey();
if (!child)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = child->Create((uintptr_t) mKey, path, mode);
if (NS_FAILED(rv))
@ -493,11 +490,8 @@ nsWindowsRegKey::IsWatching(bool *result)
nsresult
NS_NewWindowsRegKey(nsIWindowsRegKey **result)
{
*result = new nsWindowsRegKey();
if (!*result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*result);
nsRefPtr<WindowsRegKey> key = new nsWindowsRegKey();
key.forget(result);
return NS_OK;
}

View File

@ -207,15 +207,12 @@ nsDirEnumeratorUnix::GetNextFile(nsIFile **_retval)
}
nsCOMPtr<nsIFile> file = new nsLocalFile();
if (!file)
return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv = file->InitWithNativePath(mParentPath)) ||
NS_FAILED(rv = file->AppendNative(nsDependentCString(mEntry->d_name))))
return rv;
*_retval = file;
NS_ADDREF(*_retval);
file.forget(_retval);
return GetNextEntry();
}
@ -262,8 +259,6 @@ nsLocalFile::nsLocalFileConstructor(nsISupports *outer,
*aInstancePtr = nullptr;
nsCOMPtr<nsIFile> inst = new nsLocalFile();
if (!inst)
return NS_ERROR_OUT_OF_MEMORY;
return inst->QueryInterface(aIID, aInstancePtr);
}
@ -282,12 +277,8 @@ NS_IMETHODIMP
nsLocalFile::Clone(nsIFile **file)
{
// Just copy-construct ourselves
*file = new nsLocalFile(*this);
if (!*file)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*file);
nsRefPtr<nsLocalFile> copy = new nsLocalFile(*this);
copy.forget(file);
return NS_OK;
}
@ -929,8 +920,6 @@ nsLocalFile::Remove(bool recursive)
if (recursive) {
nsDirEnumeratorUnix *dir = new nsDirEnumeratorUnix();
if (!dir)
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsISimpleEnumerator> dirRef(dir); // release on exit
@ -1656,17 +1645,13 @@ nsLocalFile::SetFollowLinks(bool aFollowLinks)
NS_IMETHODIMP
nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator **entries)
{
nsDirEnumeratorUnix *dir = new nsDirEnumeratorUnix();
if (!dir)
return NS_ERROR_OUT_OF_MEMORY;
nsRefPtr<nsDirEnumeratorUnix> dir = new nsDirEnumeratorUnix();
NS_ADDREF(dir);
nsresult rv = dir->Init(this, false);
if (NS_FAILED(rv)) {
*entries = nullptr;
NS_RELEASE(dir);
} else {
*entries = dir; // transfer reference
dir.forget(entries);
}
return rv;
@ -1871,21 +1856,17 @@ nsLocalFile::Launch()
nsresult
NS_NewNativeLocalFile(const nsACString &path, bool followSymlinks, nsIFile **result)
{
nsLocalFile *file = new nsLocalFile();
if (!file)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(file);
nsRefPtr<nsLocalFile> file = new nsLocalFile();
file->SetFollowLinks(followSymlinks);
if (!path.IsEmpty()) {
nsresult rv = file->InitWithNativePath(path);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
return rv;
}
}
*result = file;
file.forget(result);
return NS_OK;
}
@ -2440,38 +2421,30 @@ NS_IMETHODIMP nsLocalFile::InitWithFile(nsIFile *aFile)
nsresult
NS_NewLocalFileWithFSRef(const FSRef* aFSRef, bool aFollowLinks, nsILocalFileMac** result)
{
nsLocalFile* file = new nsLocalFile();
if (file == nullptr)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(file);
nsRefPtr<nsLocalFile> file = new nsLocalFile();
file->SetFollowLinks(aFollowLinks);
nsresult rv = file->InitWithFSRef(aFSRef);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
return rv;
}
*result = file;
file.forget(result);
return NS_OK;
}
nsresult
NS_NewLocalFileWithCFURL(const CFURLRef aURL, bool aFollowLinks, nsILocalFileMac** result)
{
nsLocalFile* file = new nsLocalFile();
if (!file)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(file);
nsRefPtr<nsLocalFile> file = new nsLocalFile();
file->SetFollowLinks(aFollowLinks);
nsresult rv = file->InitWithCFURL(aURL);
if (NS_FAILED(rv)) {
NS_RELEASE(file);
return rv;
}
*result = file;
file.forget(result);
return NS_OK;
}