Bug 1132078 - Remove useless null checks after allocating memory with |new| from xpcom/io. r=nfroyd

This commit is contained in:
Thomas Baquet 2015-03-02 11:59:36 +01:00
parent 291379e831
commit 749f667e1b
12 changed files with 10 additions and 100 deletions

View File

@ -580,8 +580,8 @@ nsAppFileLocationProvider::GetFiles(const char* aProp,
}
*aResult = new nsPathsDirectoryEnumerator(this, keys);
#endif
NS_IF_ADDREF(*aResult);
rv = *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aResult);
rv = NS_OK;
}
if (!nsCRT::strcmp(aProp, NS_APP_SEARCH_DIR_LIST)) {
static const char* keys[] = { nullptr, NS_APP_SEARCH_DIR, NS_APP_USER_SEARCH_DIR, nullptr };
@ -590,8 +590,8 @@ nsAppFileLocationProvider::GetFiles(const char* aProp,
keys[0] = &nullstr;
}
*aResult = new nsPathsDirectoryEnumerator(this, keys);
NS_IF_ADDREF(*aResult);
rv = *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aResult);
rv = NS_OK;
}
return rv;
}

View File

@ -91,9 +91,6 @@ nsDirectoryService::GetCurrentProcessDirectory(nsIFile** aFile)
}
nsLocalFile* localFile = new nsLocalFile;
if (!localFile) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(localFile);
#ifdef XP_WIN

View File

@ -347,10 +347,6 @@ NS_NewInputStreamTeeAsync(nsIInputStream** aResult,
nsresult rv;
nsCOMPtr<nsIInputStreamTee> tee = new nsInputStreamTee();
if (!tee) {
return NS_ERROR_OUT_OF_MEMORY;
}
rv = tee->SetSource(aSource);
if (NS_FAILED(rv)) {
return rv;

View File

@ -827,10 +827,6 @@ nsLocalFile::CopyToNative(nsIFile* aNewParent, const nsACString& aNewName)
// actually create the file.
nsLocalFile* newFile = new nsLocalFile();
if (!newFile) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsCOMPtr<nsIFile> fileRef(newFile); // release on exit
rv = newFile->InitWithNativePath(newPathName);

View File

@ -457,10 +457,6 @@ static nsresult
NS_CreateShortcutResolver()
{
gResolver = new ShortcutResolver();
if (!gResolver) {
return NS_ERROR_OUT_OF_MEMORY;
}
return gResolver->Init();
}
@ -764,11 +760,7 @@ OpenDir(const nsAFlatString& aName, nsDir** aDir)
return NS_ERROR_FILE_NAME_TOO_LONG;
}
nsDir* d = PR_NEW(nsDir);
if (!d) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsDir* d = new nsDir();
nsAutoString filename(aName);
// If |aName| ends in a slash or backslash, do not append another backslash.
@ -786,7 +778,7 @@ OpenDir(const nsAFlatString& aName, nsDir** aDir)
d->handle = ::FindFirstFileW(filename.get(), &(d->data));
if (d->handle == INVALID_HANDLE_VALUE) {
PR_Free(d);
delete d;
return ConvertWinError(GetLastError());
}
d->firstEntry = true;
@ -855,8 +847,8 @@ CloseDir(nsDir*& aDir)
}
BOOL isOk = FindClose(aDir->handle);
// PR_DELETE also nulls out the passed in pointer.
PR_DELETE(aDir);
delete aDir;
aDir = nullptr;
return isOk ? NS_OK : ConvertWinError(GetLastError());
}
@ -1018,10 +1010,6 @@ nsLocalFile::nsLocalFileConstructor(nsISupports* aOuter, const nsIID& aIID,
}
nsLocalFile* inst = new nsLocalFile();
if (!inst) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = inst->QueryInterface(aIID, aInstancePtr);
if (NS_FAILED(rv)) {
delete inst;
@ -1195,10 +1183,6 @@ nsLocalFile::Clone(nsIFile** aFile)
{
// Just copy-construct ourselves
*aFile = new nsLocalFile(*this);
if (!*aFile) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aFile);
return NS_OK;
@ -1732,11 +1716,7 @@ nsLocalFile::GetVersionInfoField(const char* aField, nsAString& aResult)
return rv;
}
void* ver = calloc(size, 1);
if (!ver) {
return NS_ERROR_OUT_OF_MEMORY;
}
void* ver = moz_xcalloc(size, 1);
if (::GetFileVersionInfoW(path, 0, size, ver)) {
LANGANDCODEPAGE* translate = nullptr;
UINT pageCount;
@ -1765,7 +1745,7 @@ nsLocalFile::GetVersionInfoField(const char* aField, nsAString& aResult)
}
}
}
free(ver);
moz_free(ver);
return rv;
}
@ -2034,10 +2014,6 @@ nsLocalFile::CopyMove(nsIFile* aParentDir, const nsAString& aNewName,
newParentDir->GetTarget(target);
nsCOMPtr<nsIFile> realDest = new nsLocalFile();
if (!realDest) {
return NS_ERROR_OUT_OF_MEMORY;
}
rv = realDest->InitWithPath(target);
if (NS_FAILED(rv)) {
@ -3231,9 +3207,6 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator** aEntries)
*aEntries = nullptr;
if (mWorkingPath.EqualsLiteral("\\\\.")) {
nsDriveEnumerator* drives = new nsDriveEnumerator;
if (!drives) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(drives);
rv = drives->Init();
if (NS_FAILED(rv)) {
@ -3381,9 +3354,6 @@ nsresult
NS_NewLocalFile(const nsAString& aPath, bool aFollowLinks, nsIFile** aResult)
{
nsLocalFile* file = new nsLocalFile();
if (!file) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(file);
file->SetFollowLinks(aFollowLinks);

View File

@ -685,9 +685,6 @@ nsMultiplexInputStreamConstructor(nsISupports* aOuter,
}
nsMultiplexInputStream* inst = new nsMultiplexInputStream();
if (!inst) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(inst);
nsresult rv = inst->QueryInterface(aIID, aResult);

View File

@ -1611,10 +1611,6 @@ NS_NewPipe2(nsIAsyncInputStream** aPipeIn,
nsresult rv;
nsPipe* pipe = new nsPipe();
if (!pipe) {
return NS_ERROR_OUT_OF_MEMORY;
}
rv = pipe->Init(aNonBlockingInput,
aNonBlockingOutput,
aSegmentSize,
@ -1637,9 +1633,6 @@ nsPipeConstructor(nsISupports* aOuter, REFNSIID aIID, void** aResult)
return NS_ERROR_NO_AGGREGATION;
}
nsPipe* pipe = new nsPipe();
if (!pipe) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(pipe);
nsresult rv = pipe->QueryInterface(aIID, aResult);
NS_RELEASE(pipe);

View File

@ -130,10 +130,6 @@ nsScriptableInputStream::Create(nsISupports* aOuter, REFNSIID aIID,
}
nsScriptableInputStream* sis = new nsScriptableInputStream();
if (!sis) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(sis);
nsresult rv = sis->QueryInterface(aIID, aResult);
NS_RELEASE(sis);

View File

@ -77,10 +77,6 @@ NS_IMETHODIMP
nsStorageStream::Init(uint32_t aSegmentSize, uint32_t aMaxSize)
{
mSegmentedBuffer = new nsSegmentedBuffer();
if (!mSegmentedBuffer) {
return NS_ERROR_OUT_OF_MEMORY;
}
mSegmentSize = aSegmentSize;
mSegmentSizeLog2 = mozilla::FloorLog2(aSegmentSize);
@ -410,10 +406,6 @@ nsStorageStream::NewInputStream(int32_t aStartingOffset,
nsStorageInputStream* inputStream =
new nsStorageInputStream(this, mSegmentSize);
if (!inputStream) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(inputStream);
nsresult rv = inputStream->Seek(aStartingOffset);
@ -638,10 +630,6 @@ NS_NewStorageStream(uint32_t aSegmentSize, uint32_t aMaxSize,
nsIStorageStream** aResult)
{
nsStorageStream* storageStream = new nsStorageStream();
if (!storageStream) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(storageStream);
nsresult rv = storageStream->Init(aSegmentSize, aMaxSize);
if (NS_FAILED(rv)) {

View File

@ -609,10 +609,6 @@ NS_AsyncCopy(nsIInputStream* aSource,
copier = new nsStreamCopierOB();
}
if (!copier) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Start() takes an owning ref to the copier...
NS_ADDREF(copier);
rv = copier->Start(aSource, aSink, aTarget, aCallback, aClosure, aChunkSize,

View File

@ -381,10 +381,6 @@ NS_NewByteInputStream(nsIInputStream** aStreamResult,
NS_PRECONDITION(aStreamResult, "null out ptr");
nsStringInputStream* stream = new nsStringInputStream();
if (!stream) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(stream);
nsresult rv;
@ -427,10 +423,6 @@ NS_NewCStringInputStream(nsIInputStream** aStreamResult,
NS_PRECONDITION(aStreamResult, "null out ptr");
nsStringInputStream* stream = new nsStringInputStream();
if (!stream) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(stream);
stream->SetData(aStringToRead);
@ -451,10 +443,6 @@ nsStringInputStreamConstructor(nsISupports* aOuter, REFNSIID aIID,
}
nsStringInputStream* inst = new nsStringInputStream();
if (!inst) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(inst);
nsresult rv = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);

View File

@ -413,9 +413,6 @@ nsSimpleUnicharStreamFactory::CreateInstanceFromString(const nsAString& aString,
nsIUnicharInputStream** aResult)
{
StringUnicharInputStream* it = new StringUnicharInputStream(aString);
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aResult = it);
return NS_OK;
@ -430,10 +427,6 @@ nsSimpleUnicharStreamFactory::CreateInstanceFromUTF8Stream(
// Create converter input stream
nsRefPtr<UTF8InputStream> it = new UTF8InputStream();
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = it->Init(aStreamToWrap);
if (NS_FAILED(rv)) {
return rv;