Skip to content

Commit 779fb0d

Browse files
committed
Bug 1122740 - remove useless null checks after allocating memory with |new| r=erahm
Differential Revision: https://phabricator.services.mozilla.com/D33445 --HG-- extra : moz-landing-system : lando
1 parent 08b5f65 commit 779fb0d

22 files changed

+5
-80
lines changed

xpcom/base/nsAgg.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,6 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsAggregatedCycleCollectionParticipant,
283283
return NS_ERROR_INVALID_ARG; \
284284
\
285285
RefPtr<_InstanceClass> inst = new _InstanceClass(aOuter); \
286-
if (!inst) { \
287-
return NS_ERROR_OUT_OF_MEMORY; \
288-
} \
289-
\
290286
nsISupports* inner = inst->InnerObject(); \
291287
nsresult rv = inner->QueryInterface(aIID, aResult); \
292288
\
@@ -301,10 +297,6 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsAggregatedCycleCollectionParticipant,
301297
return NS_ERROR_INVALID_ARG; \
302298
\
303299
RefPtr<_InstanceClass> inst = new _InstanceClass(aOuter); \
304-
if (!inst) { \
305-
return NS_ERROR_OUT_OF_MEMORY; \
306-
} \
307-
\
308300
nsISupports* inner = inst->InnerObject(); \
309301
NS_ADDREF(inner); \
310302
nsresult rv = inst->_InitMethod(); \

xpcom/base/nsInterfaceRequestorAgg.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ nsresult NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor* aFirst,
5858
nsIInterfaceRequestor* aSecond,
5959
nsIInterfaceRequestor** aResult) {
6060
*aResult = new nsInterfaceRequestorAgg(aFirst, aSecond);
61-
if (!*aResult) {
62-
return NS_ERROR_OUT_OF_MEMORY;
63-
}
61+
6462
NS_ADDREF(*aResult);
6563
return NS_OK;
6664
}
@@ -70,9 +68,7 @@ nsresult NS_NewInterfaceRequestorAggregation(nsIInterfaceRequestor* aFirst,
7068
nsIEventTarget* aTarget,
7169
nsIInterfaceRequestor** aResult) {
7270
*aResult = new nsInterfaceRequestorAgg(aFirst, aSecond, aTarget);
73-
if (!*aResult) {
74-
return NS_ERROR_OUT_OF_MEMORY;
75-
}
71+
7672
NS_ADDREF(*aResult);
7773
return NS_OK;
7874
}

xpcom/components/nsCategoryManager.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ CategoryEnumerator::GetNext(nsISupports** aResult) {
9797
}
9898

9999
auto* str = new nsSupportsDependentCString(mArray[mSimpleCurItem++]);
100-
if (!str) {
101-
return NS_ERROR_OUT_OF_MEMORY;
102-
}
103100

104101
*aResult = str;
105102
NS_ADDREF(*aResult);

xpcom/ds/nsEnumeratorUtils.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,6 @@ nsresult NS_NewUnionEnumerator(nsISimpleEnumerator** aResult,
241241
*aResult = aFirstEnumerator;
242242
} else {
243243
auto* enumer = new nsUnionEnumerator(aFirstEnumerator, aSecondEnumerator);
244-
if (!enumer) {
245-
return NS_ERROR_OUT_OF_MEMORY;
246-
}
247244
*aResult = enumer;
248245
}
249246
NS_ADDREF(*aResult);

xpcom/ds/nsINIParserImpl.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ nsINIParserFactory::CreateINIParser(nsIFile* aINIFile, nsIINIParser** aResult) {
3333
*aResult = nullptr;
3434

3535
RefPtr<nsINIParserImpl> p(new nsINIParserImpl());
36-
if (!p) {
37-
return NS_ERROR_OUT_OF_MEMORY;
38-
}
3936

4037
if (aINIFile) {
4138
nsresult rv = p->Init(aINIFile);
@@ -77,9 +74,6 @@ static bool SectionCB(const char* aSection, void* aClosure) {
7774
NS_IMETHODIMP
7875
nsINIParserImpl::GetSections(nsIUTF8StringEnumerator** aResult) {
7976
nsTArray<nsCString>* strings = new nsTArray<nsCString>;
80-
if (!strings) {
81-
return NS_ERROR_OUT_OF_MEMORY;
82-
}
8377

8478
nsresult rv = mParser.GetSections(SectionCB, strings);
8579
if (NS_SUCCEEDED(rv)) {
@@ -107,9 +101,6 @@ nsINIParserImpl::GetKeys(const nsACString& aSection,
107101
}
108102

109103
nsTArray<nsCString>* strings = new nsTArray<nsCString>;
110-
if (!strings) {
111-
return NS_ERROR_OUT_OF_MEMORY;
112-
}
113104

114105
nsresult rv =
115106
mParser.GetStrings(PromiseFlatCString(aSection).get(), KeyCB, strings);

xpcom/ds/nsObserverService.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ nsresult nsObserverService::Create(nsISupports* aOuter, const nsIID& aIID,
154154

155155
RefPtr<nsObserverService> os = new nsObserverService();
156156

157-
if (!os) {
158-
return NS_ERROR_OUT_OF_MEMORY;
159-
}
160-
161157
// The memory reporter can not be immediately registered here because
162158
// the nsMemoryReporterManager may attempt to get the nsObserverService
163159
// during initialization, causing a recursive GetService.

xpcom/ds/nsStringEnumerator.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,11 @@ nsStringEnumerator::GetNext(nsISupports** aResult) {
184184

185185
if (mIsUnicode) {
186186
nsSupportsString* stringImpl = new nsSupportsString();
187-
if (!stringImpl) {
188-
return NS_ERROR_OUT_OF_MEMORY;
189-
}
190187

191188
stringImpl->SetData(mArray->ElementAt(mIndex++));
192189
*aResult = stringImpl;
193190
} else {
194191
nsSupportsCString* cstringImpl = new nsSupportsCString();
195-
if (!cstringImpl) {
196-
return NS_ERROR_OUT_OF_MEMORY;
197-
}
198192

199193
cstringImpl->SetData(mCArray->ElementAt(mIndex++));
200194
*aResult = cstringImpl;

xpcom/ds/nsVariant.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,9 +1161,7 @@ nsresult nsDiscriminatedUnion::SetFromVariant(nsIVariant* aValue) {
11611161
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
11621162
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_ASTRING);
11631163
u.mAStringValue = new nsString();
1164-
if (!u.mAStringValue) {
1165-
return NS_ERROR_OUT_OF_MEMORY;
1166-
}
1164+
11671165
rv = aValue->GetAsAString(*u.mAStringValue);
11681166
if (NS_FAILED(rv)) {
11691167
delete u.mAStringValue;
@@ -1173,9 +1171,7 @@ nsresult nsDiscriminatedUnion::SetFromVariant(nsIVariant* aValue) {
11731171
case nsIDataType::VTYPE_CSTRING:
11741172
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_CSTRING);
11751173
u.mCStringValue = new nsCString();
1176-
if (!u.mCStringValue) {
1177-
return NS_ERROR_OUT_OF_MEMORY;
1178-
}
1174+
11791175
rv = aValue->GetAsACString(*u.mCStringValue);
11801176
if (NS_FAILED(rv)) {
11811177
delete u.mCStringValue;
@@ -1185,9 +1181,7 @@ nsresult nsDiscriminatedUnion::SetFromVariant(nsIVariant* aValue) {
11851181
case nsIDataType::VTYPE_UTF8STRING:
11861182
CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_UTF8STRING);
11871183
u.mUTF8StringValue = new nsUTF8String();
1188-
if (!u.mUTF8StringValue) {
1189-
return NS_ERROR_OUT_OF_MEMORY;
1190-
}
1184+
11911185
rv = aValue->GetAsAUTF8String(*u.mUTF8StringValue);
11921186
if (NS_FAILED(rv)) {
11931187
delete u.mUTF8StringValue;

xpcom/reflect/xptcall/md/unix/xptcstubs_alpha_openbsd.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint64_t* args)
3737
dispatchParams = paramBuffer;
3838

3939
NS_ASSERTION(dispatchParams,"no place for params");
40-
if (!dispatchParams)
41-
return NS_ERROR_OUT_OF_MEMORY;
4240

4341
const uint8_t indexOfJSContext = info->IndexOfJSContext();
4442

xpcom/reflect/xptcall/md/unix/xptcstubs_arm_openbsd.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint32_t* args)
4646
dispatchParams = paramBuffer;
4747

4848
NS_ASSERTION(dispatchParams,"no place for params");
49-
if (!dispatchParams)
50-
return NS_ERROR_OUT_OF_MEMORY;
5149

5250
const uint8_t indexOfJSContext = info->IndexOfJSContext();
5351

0 commit comments

Comments
 (0)