Bug 1486690 - Remove unnecessary checks after moz_xmalloc() calls. r=glandium
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 28 Aug 2018 15:56:01 +1000
changeset 433687 8afde49af9c1f5a04c3611d6ef6de53ac98f0d8d
parent 433686 e5734413c06fefcb1247c096af3e9241235d1857
child 433688 c330fb64bcd0eb4e8ef98c0389dbd1df19b62b96
push id107158
push usernnethercote@mozilla.com
push dateWed, 29 Aug 2018 04:31:19 +0000
treeherdermozilla-inbound@74318e0ebe1e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1486690
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1486690 - Remove unnecessary checks after moz_xmalloc() calls. r=glandium There are surprisingly many of them. (Plus a couple of unnecessary checks after `new` calls that were nearby.)
docshell/base/nsDocShell.cpp
dom/base/BodyUtil.cpp
dom/crypto/CryptoBuffer.cpp
dom/events/EventListenerService.cpp
dom/file/uri/BlobURL.cpp
dom/ipc/ContentChild.cpp
dom/plugins/base/nsPluginHost.cpp
dom/plugins/base/nsPluginsDirDarwin.cpp
dom/push/PushNotifier.cpp
dom/simpledb/SDBResults.cpp
dom/xslt/xpath/txNodeSet.cpp
editor/spellchecker/EditorSpellCheck.cpp
extensions/auth/nsAuthSASL.cpp
extensions/auth/nsAuthSSPI.cpp
extensions/auth/nsHttpNegotiateAuth.cpp
extensions/spellcheck/hunspell/glue/mozHunspell.cpp
image/decoders/icon/android/nsIconChannel.cpp
image/decoders/icon/gtk/nsIconChannel.cpp
js/xpconnect/src/XPCConvert.cpp
js/xpconnect/tests/components/native/xpctest_params.cpp
layout/printing/nsPrintJob.cpp
modules/libjar/nsJARURI.cpp
netwerk/base/nsSimpleURI.cpp
netwerk/base/nsStandardURL.cpp
netwerk/cache/nsCacheEntryDescriptor.cpp
netwerk/cache/nsDiskCacheDeviceSQL.cpp
netwerk/mime/nsMIMEHeaderParamImpl.cpp
security/manager/ssl/OSKeyStore.cpp
security/manager/ssl/TransportSecurityInfo.cpp
security/manager/ssl/nsKeygenHandler.cpp
security/manager/ssl/nsNSSCertificate.cpp
security/manager/ssl/nsNTLMAuthModule.cpp
security/manager/ssl/nsRandomGenerator.cpp
security/manager/ssl/nsSSLStatus.cpp
toolkit/components/places/nsAnnotationService.cpp
toolkit/components/places/nsFaviconService.cpp
toolkit/components/places/nsNavHistoryQuery.cpp
toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
widget/GfxInfoBase.cpp
widget/gtk/nsClipboard.cpp
widget/nsPrimitiveHelpers.cpp
widget/windows/nsClipboard.cpp
xpcom/base/nsCRTGlue.cpp
xpcom/base/nsCRTGlue.h
xpcom/base/nsID.cpp
xpcom/base/nsMemory.cpp
xpcom/base/nsUUIDGenerator.cpp
xpcom/ds/nsVariant.cpp
xpcom/io/nsEscape.cpp
xpcom/io/nsSegmentedBuffer.cpp
xpcom/io/nsWildCard.cpp
xpcom/string/nsReadableUtils.cpp
xpcom/threads/nsProcessCommon.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -14309,20 +14309,16 @@ nsDocShell::GetColorMatrix(uint32_t* aMa
   NS_ENSURE_ARG_POINTER(aMatrixLen);
   *aMatrixLen = 0;
 
   NS_ENSURE_ARG_POINTER(aMatrix);
   *aMatrix = nullptr;
 
   if (mColorMatrix) {
     *aMatrix = (float*)moz_xmalloc(20 * sizeof(float));
-    if (!*aMatrix) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-
     MOZ_ASSERT(20 * sizeof(float) == sizeof(mColorMatrix->components));
     *aMatrixLen = 20;
     memcpy(*aMatrix, mColorMatrix->components, 20 * sizeof(float));
   }
 
   return NS_OK;
 }
 
--- a/dom/base/BodyUtil.cpp
+++ b/dom/base/BodyUtil.cpp
@@ -253,20 +253,16 @@ private:
       ErrorResult rv;
       mFormData->Append(name, NS_ConvertUTF8toUTF16(body), rv);
       MOZ_ASSERT(!rv.Failed());
     } else {
       // Unfortunately we've to copy the data first since all our strings are
       // going to free it. We also need fallible alloc, so we can't just use
       // ToNewCString().
       char* copy = static_cast<char*>(moz_xmalloc(body.Length()));
-      if (!copy) {
-        NS_WARNING("Failed to copy File entry body.");
-        return false;
-      }
       nsCString::const_iterator bodyIter, bodyEnd;
       body.BeginReading(bodyIter);
       body.EndReading(bodyEnd);
       char *p = copy;
       while (bodyIter != bodyEnd) {
         *p++ = *bodyIter++;
       }
       p = nullptr;
--- a/dom/crypto/CryptoBuffer.cpp
+++ b/dom/crypto/CryptoBuffer.cpp
@@ -170,19 +170,16 @@ CryptoBuffer::ToArrayBuffer(JSContext* a
 bool
 CryptoBuffer::ToNewUnsignedBuffer(uint8_t** aBuf, uint32_t* aBufLen) const
 {
   MOZ_ASSERT(aBuf);
   MOZ_ASSERT(aBufLen);
 
   uint32_t dataLen = Length();
   uint8_t* tmp = reinterpret_cast<uint8_t*>(moz_xmalloc(dataLen));
-  if (NS_WARN_IF(!tmp)) {
-    return false;
-  }
 
   memcpy(tmp, Elements(), dataLen);
   *aBuf = tmp;
   *aBufLen = dataLen;
   return true;
 }
 
 // "BigInt" comes from the WebCrypto spec
--- a/dom/events/EventListenerService.cpp
+++ b/dom/events/EventListenerService.cpp
@@ -263,19 +263,17 @@ EventListenerService::GetEventTargetChai
                                           nullptr, nullptr, nullptr, &targets);
   NS_ENSURE_SUCCESS(rv, rv);
   int32_t count = targets.Length();
   if (count == 0) {
     return NS_OK;
   }
 
   *aOutArray =
-    static_cast<EventTarget**>(
-      moz_xmalloc(sizeof(EventTarget*) * count));
-  NS_ENSURE_TRUE(*aOutArray, NS_ERROR_OUT_OF_MEMORY);
+    static_cast<EventTarget**>(moz_xmalloc(sizeof(EventTarget*) * count));
 
   for (int32_t i = 0; i < count; ++i) {
     NS_ADDREF((*aOutArray)[i] = targets[i]);
   }
   *aCount = count;
 
   return NS_OK;
 }
--- a/dom/file/uri/BlobURL.cpp
+++ b/dom/file/uri/BlobURL.cpp
@@ -217,17 +217,16 @@ BlobURL::GetClassDescription(nsACString&
 }
 
 NS_IMETHODIMP
 BlobURL::GetClassID(nsCID * *aClassID)
 {
   // Make sure to modify any subclasses as needed if this ever
   // changes to not call the virtual GetClassIDNoAlloc.
   *aClassID = (nsCID*) moz_xmalloc(sizeof(nsCID));
-  NS_ENSURE_TRUE(*aClassID, NS_ERROR_OUT_OF_MEMORY);
 
   return GetClassIDNoAlloc(*aClassID);
 }
 
 NS_IMETHODIMP
 BlobURL::GetFlags(uint32_t *aFlags)
 {
   *aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -4024,19 +4024,16 @@ GetStringValueFromBundlePlist(const nsAS
   if (valueCString) {
     aValue.Assign(valueCString);
     return NS_OK;
   }
 
   CFIndex maxLength =
     CFStringGetMaximumSizeForEncoding(valueLength, kCFStringEncodingUTF8) + 1;
   char* valueBuffer = static_cast<char*>(moz_xmalloc(maxLength));
-  if (!valueBuffer) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   if (!CFStringGetCString(value, valueBuffer, maxLength,
                           kCFStringEncodingUTF8)) {
     free(valueBuffer);
     return NS_ERROR_FAILURE;
   }
 
   aValue.Assign(valueBuffer);
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -1160,18 +1160,16 @@ nsPluginHost::GetPluginTags(uint32_t* aP
   RefPtr<nsPluginTag> plugin = mPlugins;
   while (plugin != nullptr) {
     count++;
     plugin = plugin->mNext;
   }
 
   *aResults = static_cast<nsIPluginTag**>
                          (moz_xmalloc((fakeCount + count) * sizeof(**aResults)));
-  if (!*aResults)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   *aPluginCount = count + fakeCount;
 
   plugin = mPlugins;
   for (uint32_t i = 0; i < count; i++) {
     (*aResults)[i] = plugin;
     NS_ADDREF((*aResults)[i]);
     plugin = plugin->mNext;
@@ -3638,18 +3636,17 @@ nsPluginHost::ParsePostBufferToFixHeader
     // of ContentLenHeader value in this case.
 
     newBufferLen = dataLen + headersLen;
     // in case there were single LFs in headers
     // reserve an extra space for CR will be added before each single LF
     int cntSingleLF = singleLF.Length();
     newBufferLen += cntSingleLF;
 
-    if (!(*outPostData = p = (char*)moz_xmalloc(newBufferLen)))
-      return NS_ERROR_OUT_OF_MEMORY;
+    *outPostData = p = (char*)moz_xmalloc(newBufferLen);
 
     // deal with single LF
     const char *s = inPostData;
     if (cntSingleLF) {
       for (int i=0; i<cntSingleLF; i++) {
         const char *plf = singleLF.ElementAt(i); // ptr to single LF in headers
         int n = plf - s; // bytes to copy
         if (n) { // for '\n\n' there is nothing to memcpy
@@ -3667,18 +3664,17 @@ nsPluginHost::ParsePostBufferToFixHeader
       memcpy(p, s, headersLen); // copy the rest
       p += headersLen;
     }
   } else  if (dataLen) { // no ContentLenHeader is found but there is a data
     // make new output buffer big enough
     // to keep ContentLenHeader+value followed by data
     uint32_t l = sizeof(ContentLenHeader) + sizeof(CRLFCRLF) + 32;
     newBufferLen = dataLen + l;
-    if (!(*outPostData = p = (char*)moz_xmalloc(newBufferLen)))
-      return NS_ERROR_OUT_OF_MEMORY;
+    *outPostData = p = (char*)moz_xmalloc(newBufferLen);
     headersLen = snprintf(p, l,"%s: %u%s", ContentLenHeader, dataLen, CRLFCRLF);
     if (headersLen == l) { // if snprintf has ate all extra space consider this as an error
       free(p);
       *outPostData = 0;
       return NS_ERROR_FAILURE;
     }
     p += headersLen;
     newBufferLen = headersLen + dataLen;
--- a/dom/plugins/base/nsPluginsDirDarwin.cpp
+++ b/dom/plugins/base/nsPluginsDirDarwin.cpp
@@ -202,35 +202,25 @@ static void ParsePlistPluginInfo(nsPlugi
   }
 
   AutoCFTypeObject mimeDictAutorelease(mimeDict);
   int mimeDictKeyCount = ::CFDictionaryGetCount(mimeDict);
 
   // Allocate memory for mime data
   int mimeDataArraySize = mimeDictKeyCount * sizeof(char*);
   info.fMimeTypeArray = static_cast<char**>(moz_xmalloc(mimeDataArraySize));
-  if (!info.fMimeTypeArray)
-    return;
   memset(info.fMimeTypeArray, 0, mimeDataArraySize);
   info.fExtensionArray = static_cast<char**>(moz_xmalloc(mimeDataArraySize));
-  if (!info.fExtensionArray)
-    return;
   memset(info.fExtensionArray, 0, mimeDataArraySize);
   info.fMimeDescriptionArray = static_cast<char**>(moz_xmalloc(mimeDataArraySize));
-  if (!info.fMimeDescriptionArray)
-    return;
   memset(info.fMimeDescriptionArray, 0, mimeDataArraySize);
 
   // Allocate memory for mime dictionary keys and values
   mozilla::UniquePtr<CFTypeRef[]> keys(new CFTypeRef[mimeDictKeyCount]);
-  if (!keys)
-    return;
   mozilla::UniquePtr<CFTypeRef[]> values(new CFTypeRef[mimeDictKeyCount]);
-  if (!values)
-    return;
 
   info.fVariantCount = 0;
 
   ::CFDictionaryGetKeysAndValues(mimeDict, keys.get(), values.get());
   for (int i = 0; i < mimeDictKeyCount; i++) {
     CFTypeRef mimeString = keys[i];
     if (!mimeString || ::CFGetTypeID(mimeString) != ::CFStringGetTypeID()) {
       continue;
@@ -329,20 +319,18 @@ nsresult nsPluginFile::LoadPlugin(PRLibr
 #endif
   return NS_OK;
 }
 
 static char* p2cstrdup(StringPtr pstr)
 {
   int len = pstr[0];
   char* cstr = static_cast<char*>(moz_xmalloc(len + 1));
-  if (cstr) {
-    memmove(cstr, pstr + 1, len);
-    cstr[len] = '\0';
-  }
+  memmove(cstr, pstr + 1, len);
+  cstr[len] = '\0';
   return cstr;
 }
 
 static char* GetNextPluginStringFromHandle(Handle h, short *index)
 {
   char *ret = p2cstrdup((unsigned char*)(*h + *index));
   *index += (ret ? strlen(ret) : 0) + 1;
   return ret;
@@ -442,25 +430,19 @@ nsresult nsPluginFile::GetPluginInfo(nsP
       if (mi.infoStrings)  // it's possible some plugins have infoStrings missing
         ::HLock(mi.infoStrings);
     }
   }
 
   // Fill in the info struct based on the data in the BPSupportedMIMETypes struct
   int variantCount = info.fVariantCount;
   info.fMimeTypeArray = static_cast<char**>(moz_xmalloc(variantCount * sizeof(char*)));
-  if (!info.fMimeTypeArray)
-    return NS_ERROR_OUT_OF_MEMORY;
   info.fExtensionArray = static_cast<char**>(moz_xmalloc(variantCount * sizeof(char*)));
-  if (!info.fExtensionArray)
-    return NS_ERROR_OUT_OF_MEMORY;
   if (mi.infoStrings) {
     info.fMimeDescriptionArray = static_cast<char**>(moz_xmalloc(variantCount * sizeof(char*)));
-    if (!info.fMimeDescriptionArray)
-      return NS_ERROR_OUT_OF_MEMORY;
   }
   short mimeIndex = 2;
   short descriptionIndex = 2;
   for (int i = 0; i < variantCount; i++) {
     info.fMimeTypeArray[i] = GetNextPluginStringFromHandle(mi.typeStrings, &mimeIndex);
     info.fExtensionArray[i] = GetNextPluginStringFromHandle(mi.typeStrings, &mimeIndex);
     if (mi.infoStrings)
       info.fMimeDescriptionArray[i] = GetNextPluginStringFromHandle(mi.infoStrings, &descriptionIndex);
--- a/dom/push/PushNotifier.cpp
+++ b/dom/push/PushNotifier.cpp
@@ -219,19 +219,16 @@ PushData::Binary(uint32_t* aDataLen, uin
 
   *aData = nullptr;
   if (mData.IsEmpty()) {
     *aDataLen = 0;
     return NS_OK;
   }
   uint32_t length = mData.Length();
   uint8_t* data = static_cast<uint8_t*>(moz_xmalloc(length * sizeof(uint8_t)));
-  if (!data) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
   memcpy(data, mData.Elements(), length * sizeof(uint8_t));
   *aDataLen = length;
   *aData = data;
   return NS_OK;
 }
 
 PushMessage::PushMessage(nsIPrincipal* aPrincipal, nsIPushData* aData)
   : mPrincipal(aPrincipal)
--- a/dom/simpledb/SDBResults.cpp
+++ b/dom/simpledb/SDBResults.cpp
@@ -29,19 +29,16 @@ SDBResult::GetAsArray(uint32_t* aDataLen
     *aDataLen = 0;
     *aData = nullptr;
     return NS_OK;
   }
 
   uint32_t length = mData.Length();
 
   uint8_t* data = static_cast<uint8_t*>(moz_xmalloc(length * sizeof(uint8_t)));
-  if (!data) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   memcpy(data, mData.BeginReading(), length * sizeof(uint8_t));
 
   *aDataLen = length;
   *aData = data;
   return NS_OK;
 }
 
--- a/dom/xslt/xpath/txNodeSet.cpp
+++ b/dom/xslt/xpath/txNodeSet.cpp
@@ -520,22 +520,18 @@ bool txNodeSet::ensureGrowSize(int32_t a
     // This isn't 100% safe. But until someone manages to make a 1gig nodeset
     // it should be ok.
     int32_t newLength = std::max(oldLength, kTxNodeSetMinSize);
 
     while (newLength < ensureSize) {
         newLength *= kTxNodeSetGrowFactor;
     }
 
-    txXPathNode* newArr = static_cast<txXPathNode*>
-                                     (moz_xmalloc(newLength *
-                                                         sizeof(txXPathNode)));
-    if (!newArr) {
-        return false;
-    }
+    txXPathNode* newArr =
+      static_cast<txXPathNode*>(moz_xmalloc(newLength * sizeof(txXPathNode)));
 
     txXPathNode* dest = newArr;
     if (mDirection == kReversed) {
         dest += newLength - oldSize;
     }
 
     if (oldSize > 0) {
         LOG_CHUNK_MOVE(mStart, dest, oldSize);
--- a/editor/spellchecker/EditorSpellCheck.cpp
+++ b/editor/spellchecker/EditorSpellCheck.cpp
@@ -580,29 +580,25 @@ EditorSpellCheck::GetDictionaryList(char
   char16_t **tmpPtr = 0;
 
   if (dictList.IsEmpty()) {
     // If there are no dictionaries, return an array containing
     // one element and a count of one.
 
     tmpPtr = (char16_t **)moz_xmalloc(sizeof(char16_t *));
 
-    NS_ENSURE_TRUE(tmpPtr, NS_ERROR_OUT_OF_MEMORY);
-
     *tmpPtr          = 0;
     *aDictionaryList = tmpPtr;
     *aCount          = 0;
 
     return NS_OK;
   }
 
   tmpPtr = (char16_t **)moz_xmalloc(sizeof(char16_t *) * dictList.Length());
 
-  NS_ENSURE_TRUE(tmpPtr, NS_ERROR_OUT_OF_MEMORY);
-
   *aDictionaryList = tmpPtr;
   *aCount          = dictList.Length();
 
   for (uint32_t i = 0; i < *aCount; i++) {
     tmpPtr[i] = ToNewUnicode(dictList[i]);
   }
 
   return rv;
--- a/extensions/auth/nsAuthSASL.cpp
+++ b/extensions/auth/nsAuthSASL.cpp
@@ -100,20 +100,16 @@ nsAuthSASL::GetNextToken(const void *inT
         // If we were doing security layers then we'd care what the
         // server had sent us. We're not, so all we had to do was make
         // sure that the signature was correct with the above unwrap()
         free(unwrappedToken);
 
         NS_CopyUnicodeToNative(mUsername, userbuf);
         messageLen = userbuf.Length() + 4 + 1;
         message = (char *)moz_xmalloc(messageLen);
-        if (!message) {
-          Reset();
-          return NS_ERROR_OUT_OF_MEMORY;
-        }
         message[0] = 0x01; // No security layer
         message[1] = 0x00;
         message[2] = 0x00;
         message[3] = 0x00; // Maxbuf must be zero if we've got no sec layer
         strcpy(message+4, userbuf.get());
         // Userbuf should not be nullptr terminated, so trim the trailing nullptr
         // when wrapping the message
         rv = mInnerModule->Wrap((void *) message, messageLen-1, false,
--- a/extensions/auth/nsAuthSSPI.cpp
+++ b/extensions/auth/nsAuthSSPI.cpp
@@ -336,18 +336,16 @@ nsAuthSSPI::GetNextToken(const void *inT
 
     if (inToken) {
         if (mIsFirst) {
             // First time if it comes with a token,
             // the token represents the server certificate.
             mIsFirst = false;
             mCertDERLength = inTokenLen;
             mCertDERData = moz_xmalloc(inTokenLen);
-            if (!mCertDERData)
-                return NS_ERROR_OUT_OF_MEMORY;
             memcpy(mCertDERData, inToken, inTokenLen);
 
             // We are starting a new authentication sequence.
             // If we have already initialized our
             // security context, then we're in trouble because it means that the
             // first sequence failed.  We need to bail or else we might end up in
             // an infinite loop.
             if (mCtxt.dwLower || mCtxt.dwUpper) {
@@ -380,19 +378,16 @@ nsAuthSSPI::GetNextToken(const void *inT
 
                 // Then add it to the array of sec buffers accordingly.
                 ib[ibd.cBuffers].BufferType = SECBUFFER_CHANNEL_BINDINGS;
                 ib[ibd.cBuffers].cbBuffer =
                         pendpoint_binding.cbApplicationDataLength
                         + pendpoint_binding.dwApplicationDataOffset;
 
                 sspi_cbt = (char *) moz_xmalloc(ib[ibd.cBuffers].cbBuffer);
-                if (!sspi_cbt){
-                    return NS_ERROR_OUT_OF_MEMORY;
-                }
 
                 // Helper to write in the memory block that stores the CBT
                 char* sspi_cbt_ptr = sspi_cbt;
 
                 ib[ibd.cBuffers].pvBuffer = sspi_cbt;
                 ibd.cBuffers++;
 
                 memcpy(sspi_cbt_ptr, &pendpoint_binding,
@@ -455,21 +450,16 @@ nsAuthSSPI::GetNextToken(const void *inT
     }
 
     obd.ulVersion = SECBUFFER_VERSION;
     obd.cBuffers = 1;
     obd.pBuffers = &ob;
     ob.BufferType = SECBUFFER_TOKEN;
     ob.cbBuffer = mMaxTokenLen;
     ob.pvBuffer = moz_xmalloc(ob.cbBuffer);
-    if (!ob.pvBuffer){
-        if (sspi_cbt)
-            free(sspi_cbt);
-        return NS_ERROR_OUT_OF_MEMORY;
-    }
     memset(ob.pvBuffer, 0, ob.cbBuffer);
 
     NS_ConvertUTF8toUTF16 wSN(mServiceName);
     SEC_WCHAR *sn = (SEC_WCHAR *) wSN.get();
 
     rc = (sspi->InitializeSecurityContextW)(&mCred,
                                             ctxIn,
                                             sn,
@@ -524,18 +514,16 @@ nsAuthSSPI::Unwrap(const void *inToken,
     ibd.cBuffers = 2;
     ibd.pBuffers = ib;
     ibd.ulVersion = SECBUFFER_VERSION;
 
     // SSPI Buf
     ib[0].BufferType = SECBUFFER_STREAM;
     ib[0].cbBuffer = inTokenLen;
     ib[0].pvBuffer = moz_xmalloc(ib[0].cbBuffer);
-    if (!ib[0].pvBuffer)
-        return NS_ERROR_OUT_OF_MEMORY;
 
     memcpy(ib[0].pvBuffer, inToken, inTokenLen);
 
     // app data
     ib[1].BufferType = SECBUFFER_DATA;
     ib[1].cbBuffer = 0;
     ib[1].pvBuffer = nullptr;
 
@@ -617,48 +605,36 @@ nsAuthSSPI::Wrap(const void *inToken,
     ibd.pBuffers = bufs.ib;
     ibd.ulVersion = SECBUFFER_VERSION;
 
     // SSPI
     bufs.ib[0].cbBuffer = sizes.cbSecurityTrailer;
     bufs.ib[0].BufferType = SECBUFFER_TOKEN;
     bufs.ib[0].pvBuffer = moz_xmalloc(sizes.cbSecurityTrailer);
 
-    if (!bufs.ib[0].pvBuffer)
-        return NS_ERROR_OUT_OF_MEMORY;
-
     // APP Data
     bufs.ib[1].BufferType = SECBUFFER_DATA;
     bufs.ib[1].pvBuffer = moz_xmalloc(inTokenLen);
     bufs.ib[1].cbBuffer = inTokenLen;
 
-    if (!bufs.ib[1].pvBuffer)
-        return NS_ERROR_OUT_OF_MEMORY;
-
     memcpy(bufs.ib[1].pvBuffer, inToken, inTokenLen);
 
     // SSPI
     bufs.ib[2].BufferType = SECBUFFER_PADDING;
     bufs.ib[2].cbBuffer = sizes.cbBlockSize;
     bufs.ib[2].pvBuffer = moz_xmalloc(bufs.ib[2].cbBuffer);
 
-    if (!bufs.ib[2].pvBuffer)
-        return NS_ERROR_OUT_OF_MEMORY;
-
     rc = (sspi->EncryptMessage)(&mCtxt,
           confidential ? 0 : KERB_WRAP_NO_ENCRYPT,
          &ibd, 0);
 
     if (SEC_SUCCESS(rc)) {
         int len  = bufs.ib[0].cbBuffer + bufs.ib[1].cbBuffer + bufs.ib[2].cbBuffer;
         char *p = (char *) moz_xmalloc(len);
 
-        if (!p)
-            return NS_ERROR_OUT_OF_MEMORY;
-
         *outToken = (void *) p;
         *outTokenLen = len;
 
         memcpy(p, bufs.ib[0].pvBuffer, bufs.ib[0].cbBuffer);
         p += bufs.ib[0].cbBuffer;
 
         memcpy(p,bufs.ib[1].pvBuffer, bufs.ib[1].cbBuffer);
         p += bufs.ib[1].cbBuffer;
--- a/extensions/auth/nsHttpNegotiateAuth.cpp
+++ b/extensions/auth/nsHttpNegotiateAuth.cpp
@@ -578,20 +578,17 @@ nsHttpNegotiateAuth::GenerateCredentials
     if (!encoded_token)
         return NS_ERROR_OUT_OF_MEMORY;
 
     LOG(("  Sending a token of length %d\n", outTokenLen));
 
     // allocate a buffer sizeof("Negotiate" + " " + b64output_token + "\0")
     const int bufsize = kNegotiateLen + 1 + strlen(encoded_token) + 1;
     *creds = (char *) moz_xmalloc(bufsize);
-    if (MOZ_UNLIKELY(!*creds))
-        rv = NS_ERROR_OUT_OF_MEMORY;
-    else
-        snprintf(*creds, bufsize, "%s %s", kNegotiate, encoded_token);
+    snprintf(*creds, bufsize, "%s %s", kNegotiate, encoded_token);
 
     PR_Free(encoded_token); // PL_Base64Encode() uses PR_Malloc().
     return rv;
 }
 
 bool
 nsHttpNegotiateAuth::TestBoolPref(const char *pref)
 {
--- a/extensions/spellcheck/hunspell/glue/mozHunspell.cpp
+++ b/extensions/spellcheck/hunspell/glue/mozHunspell.cpp
@@ -466,62 +466,54 @@ mozHunspell::Suggest(const nsAString& aW
   rv = ConvertCharset(aWord, charsetWord);
   NS_ENSURE_SUCCESS(rv, rv);
 
   std::vector<std::string> suggestions = mHunspell->suggest(charsetWord);
   *aSuggestionCount = static_cast<uint32_t>(suggestions.size());
 
   if (*aSuggestionCount) {
     *aSuggestions  = (char16_t **)moz_xmalloc(*aSuggestionCount * sizeof(char16_t *));
-    if (*aSuggestions) {
-      uint32_t index = 0;
-      for (index = 0; index < *aSuggestionCount && NS_SUCCEEDED(rv); ++index) {
-        // If the IDL used an array of AString, we could use
-        // Encoding::DecodeWithoutBOMHandling() here.
-        // Convert the suggestion to utf16
-        Span<const char> charSrc(suggestions[index]);
-        auto src = AsBytes(charSrc);
-        CheckedInt<size_t> needed =
-          mDecoder->MaxUTF16BufferLength(src.Length());
-        if (!needed.isValid()) {
-          rv = NS_ERROR_OUT_OF_MEMORY;
-          break;
-        }
-        size_t dstLen = needed.value();
-        needed += 1;
-        needed *= sizeof(char16_t);
-        if (!needed.isValid()) {
-          rv = NS_ERROR_OUT_OF_MEMORY;
-          break;
-        }
-        (*aSuggestions)[index] = (char16_t*)moz_xmalloc(needed.value());
-        if (!((*aSuggestions)[index])) {
-          rv = NS_ERROR_OUT_OF_MEMORY;
-          break;
-        }
-        auto dst = MakeSpan((*aSuggestions)[index], dstLen);
-        uint32_t result;
-        size_t read;
-        size_t written;
-        bool hadErrors;
-        Tie(result, read, written, hadErrors) =
-          mDecoder->DecodeToUTF16(src, dst, true);
-        MOZ_ASSERT(result == kInputEmpty);
-        MOZ_ASSERT(read == src.Length());
-        MOZ_ASSERT(written <= dstLen);
-        Unused << hadErrors;
-        (*aSuggestions)[index][written] = 0;
-        mDecoder->Encoding()->NewDecoderWithoutBOMHandlingInto(*mDecoder);
+    uint32_t index = 0;
+    for (index = 0; index < *aSuggestionCount && NS_SUCCEEDED(rv); ++index) {
+      // If the IDL used an array of AString, we could use
+      // Encoding::DecodeWithoutBOMHandling() here.
+      // Convert the suggestion to utf16
+      Span<const char> charSrc(suggestions[index]);
+      auto src = AsBytes(charSrc);
+      CheckedInt<size_t> needed =
+        mDecoder->MaxUTF16BufferLength(src.Length());
+      if (!needed.isValid()) {
+        rv = NS_ERROR_OUT_OF_MEMORY;
+        break;
       }
+      size_t dstLen = needed.value();
+      needed += 1;
+      needed *= sizeof(char16_t);
+      if (!needed.isValid()) {
+        rv = NS_ERROR_OUT_OF_MEMORY;
+        break;
+      }
+      (*aSuggestions)[index] = (char16_t*)moz_xmalloc(needed.value());
+      auto dst = MakeSpan((*aSuggestions)[index], dstLen);
+      uint32_t result;
+      size_t read;
+      size_t written;
+      bool hadErrors;
+      Tie(result, read, written, hadErrors) =
+        mDecoder->DecodeToUTF16(src, dst, true);
+      MOZ_ASSERT(result == kInputEmpty);
+      MOZ_ASSERT(read == src.Length());
+      MOZ_ASSERT(written <= dstLen);
+      Unused << hadErrors;
+      (*aSuggestions)[index][written] = 0;
+      mDecoder->Encoding()->NewDecoderWithoutBOMHandlingInto(*mDecoder);
+    }
 
-      if (NS_FAILED(rv))
-        NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(index, *aSuggestions); // free the char16_t strings up to the point at which the error occurred
-    }
-    else // if (*aSuggestions)
-      rv = NS_ERROR_OUT_OF_MEMORY;
+    if (NS_FAILED(rv))
+      NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(index, *aSuggestions); // free the char16_t strings up to the point at which the error occurred
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 mozHunspell::Observe(nsISupports* aSubj, const char *aTopic,
                     const char16_t *aData)
--- a/image/decoders/icon/android/nsIconChannel.cpp
+++ b/image/decoders/icon/android/nsIconChannel.cpp
@@ -69,17 +69,16 @@ moz_icon_to_channel(nsIURI* aURI, const 
   int width = aIconSize;
   int height = aIconSize;
 
   // moz-icon data should have two bytes for the size,
   // then the ARGB pixel values with pre-multiplied Alpha
   const int channels = 4;
   long int buf_size = 2 + channels * height * width;
   uint8_t* const buf = (uint8_t*)moz_xmalloc(buf_size);
-  NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
   uint8_t* out = buf;
 
   *(out++) = width;
   *(out++) = height;
 
   nsresult rv;
   if (XRE_IsParentProcess()) {
     rv = GetIconForExtension(aFileExt, aIconSize, out);
--- a/image/decoders/icon/gtk/nsIconChannel.cpp
+++ b/image/decoders/icon/gtk/nsIconChannel.cpp
@@ -45,17 +45,16 @@ moz_gdk_pixbuf_to_channel(GdkPixbuf* aPi
                  gdk_pixbuf_get_bits_per_sample(aPixbuf) == 8 &&
                  gdk_pixbuf_get_has_alpha(aPixbuf) &&
                  gdk_pixbuf_get_n_channels(aPixbuf) == 4,
                  NS_ERROR_UNEXPECTED);
 
   const int n_channels = 4;
   gsize buf_size = 2 + n_channels * height * width;
   uint8_t* const buf = (uint8_t*)moz_xmalloc(buf_size);
-  NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
   uint8_t* out = buf;
 
   *(out++) = width;
   *(out++) = height;
 
   const guchar* const pixels = gdk_pixbuf_get_pixels(aPixbuf);
   int rowextra = gdk_pixbuf_get_rowstride(aPixbuf) - width * n_channels;
 
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -687,19 +687,16 @@ XPCConvert::JSData2Native(JSContext* cx,
                     *pErr = NS_ERROR_XPC_NOT_ENOUGH_CHARS_IN_STRING;
                 return false;
             }
             if (length < arrlen) {
                 length = arrlen;
             }
         }
         char* buffer = static_cast<char*>(moz_xmalloc(length + 1));
-        if (!buffer) {
-            return false;
-        }
         if (!JS_EncodeStringToBuffer(cx, str, buffer, length)) {
             free(buffer);
             return false;
         }
         buffer[length] = '\0';
         *((void**)d) = buffer;
         return true;
     }
@@ -730,20 +727,17 @@ XPCConvert::JSData2Native(JSContext* cx,
                 return false;
             }
             if (len < arrlen) {
                 len = arrlen;
             }
         }
 
         size_t byte_len = (len+1)*sizeof(char16_t);
-        if (!(*((void**)d) = moz_xmalloc(byte_len))) {
-            // XXX should report error
-            return false;
-        }
+        *((void**)d) = moz_xmalloc(byte_len);
         mozilla::Range<char16_t> destChars(*((char16_t**)d), len + 1);
         if (!JS_CopyStringChars(cx, destChars, str))
             return false;
         destChars[len] = 0;
 
         return true;
     }
 
@@ -908,21 +902,16 @@ XPCConvert::JSData2Native(JSContext* cx,
                 if (pErr)
                     *pErr = NS_ERROR_XPC_NOT_ENOUGH_ELEMENTS_IN_ARRAY;
                 return nullptr;
             }
             *aLength = arrlen;
 
             // Allocate the backing buffer & return it.
             *dest = moz_xmalloc(*aLength * elty.Stride());
-            if (!*dest) {
-                if (pErr)
-                    *pErr = NS_ERROR_OUT_OF_MEMORY;
-                return nullptr;
-            }
             return *dest;
         });
 
         if (!ok && *dest) {
             // An error occurred, free any allocated backing buffer.
             free(*dest);
             *dest = nullptr;
         }
--- a/js/xpconnect/tests/components/native/xpctest_params.cpp
+++ b/js/xpconnect/tests/components/native/xpctest_params.cpp
@@ -53,26 +53,22 @@ nsXPCTestParams::~nsXPCTestParams()
 //             null-terminated strings.
 //   'TAKE_OWNERSHIP' is one of the macros above.
 #define BUFFER_METHOD_IMPL(type, padding, TAKE_OWNERSHIP) {                   \
     uint32_t elemSize = sizeof(type);                                         \
                                                                               \
     /* Copy b into rv. */                                                     \
     *rvLength = *bLength;                                                     \
     *rv = static_cast<type*>(moz_xmalloc(elemSize * (*bLength + padding)));   \
-    if (!*rv)                                                                 \
-        return NS_ERROR_OUT_OF_MEMORY;                                        \
     memcpy(*rv, *b, elemSize * (*bLength + padding));                         \
                                                                               \
     /* Copy a into b. */                                                      \
     *bLength = aLength;                                                       \
     free(*b);                                                                 \
     *b = static_cast<type*>(moz_xmalloc(elemSize * (aLength + padding)));     \
-    if (!*b)                                                                  \
-        return NS_ERROR_OUT_OF_MEMORY;                                        \
     memcpy(*b, a, elemSize * (aLength + padding));                            \
                                                                               \
     /* We need to take ownership of the data we got from a,                   \
        since the caller owns it. */                                           \
     for (unsigned i = 0; i < *bLength + padding; ++i)                         \
         TAKE_OWNERSHIP((*b)[i]);                                              \
                                                                               \
     return NS_OK;                                                             \
@@ -265,18 +261,16 @@ NS_IMETHODIMP nsXPCTestParams::TestInter
     // and leave no trace, XPConnect won't Release it. Since we also need to
     // return an already-AddRef'd pointer in rv, we don't need to do anything
     // special here.
     *rv = *b;
 
     // rvIID is out-only, so nobody allocated an IID buffer for us. Do that now,
     // and store b's IID in the new buffer.
     *rvIID = static_cast<nsIID*>(moz_xmalloc(sizeof(nsID)));
-    if (!*rvIID)
-        return NS_ERROR_OUT_OF_MEMORY;
     **rvIID = **bIID;
 
     // Copy the interface pointer from a to b. Since a is in-only, XPConnect will
     // release it upon completion of the call. AddRef it for b.
     *b = a;
     static_cast<nsISupports*>(*b)->AddRef();
 
     // We already had a buffer allocated for b's IID, so we can re-use it.
@@ -290,18 +284,16 @@ NS_IMETHODIMP nsXPCTestParams::TestInter
                                                     uint32_t* bLength, nsIID** bIID,
                                                     void*** b,
                                                     uint32_t* rvLength, nsIID** rvIID,
                                                     void*** rv)
 {
     // Transfer the IIDs. See the comments in TestInterfaceIs (above) for an
     // explanation of what we're doing.
     *rvIID = static_cast<nsIID*>(moz_xmalloc(sizeof(nsID)));
-    if (!*rvIID)
-        return NS_ERROR_OUT_OF_MEMORY;
     **rvIID = **bIID;
     **bIID = *aIID;
 
     // The macro is agnostic to the actual interface types, so we can re-use code here.
     //
     // Do this second, since the macro returns.
     BUFFER_METHOD_IMPL(void*, 0, TAKE_OWNERSHIP_INTERFACE);
 }
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -1148,18 +1148,16 @@ nsPrintJob::EnumerateDocumentNames(uint3
   NS_ENSURE_ARG(aCount);
   NS_ENSURE_ARG_POINTER(aResult);
 
   *aCount = 0;
   *aResult = nullptr;
 
   int32_t     numDocs = mPrt->mPrintDocList.Length();
   char16_t** array   = (char16_t**) moz_xmalloc(numDocs * sizeof(char16_t*));
-  if (!array)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   for (int32_t i=0;i<numDocs;i++) {
     nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i);
     NS_ASSERTION(po, "nsPrintObject can't be null!");
     nsAutoString docTitleStr;
     nsAutoString docURLStr;
     GetDocumentTitleAndURL(po->mDocument, docTitleStr, docURLStr);
 
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -181,18 +181,16 @@ nsJARURI::GetClassDescription(nsACString
     aClassDescription.SetIsVoid(true);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsJARURI::GetClassID(nsCID * *aClassID)
 {
     *aClassID = (nsCID*) moz_xmalloc(sizeof(nsCID));
-    if (!*aClassID)
-        return NS_ERROR_OUT_OF_MEMORY;
     return GetClassIDNoAlloc(*aClassID);
 }
 
 NS_IMETHODIMP
 nsJARURI::GetFlags(uint32_t *aFlags)
 {
     // XXX We implement THREADSAFE addref/release, but probably shouldn't.
     *aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
--- a/netwerk/base/nsSimpleURI.cpp
+++ b/netwerk/base/nsSimpleURI.cpp
@@ -720,18 +720,16 @@ nsSimpleURI::GetClassDescription(nsACStr
 }
 
 NS_IMETHODIMP
 nsSimpleURI::GetClassID(nsCID * *aClassID)
 {
     // Make sure to modify any subclasses as needed if this ever
     // changes to not call the virtual GetClassIDNoAlloc.
     *aClassID = (nsCID*) moz_xmalloc(sizeof(nsCID));
-    if (!*aClassID)
-        return NS_ERROR_OUT_OF_MEMORY;
     return GetClassIDNoAlloc(*aClassID);
 }
 
 NS_IMETHODIMP
 nsSimpleURI::GetFlags(uint32_t *aFlags)
 {
     *aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
     return NS_OK;
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -1105,21 +1105,19 @@ nsStandardURL::AppendToSubstring(uint32_
 
     uint32_t tailLen = strlen(tail);
 
     // Check for int overflow for proposed length of combined string
     if (UINT32_MAX - ((uint32_t)len + 1) < tailLen)
         return nullptr;
 
     char *result = (char *) moz_xmalloc(len + tailLen + 1);
-    if (result) {
-        memcpy(result, mSpec.get() + pos, len);
-        memcpy(result + len, tail, tailLen);
-        result[len + tailLen] = '\0';
-    }
+    memcpy(result, mSpec.get() + pos, len);
+    memcpy(result + len, tail, tailLen);
+    result[len + tailLen] = '\0';
     return result;
 }
 
 nsresult
 nsStandardURL::ReadSegment(nsIBinaryInputStream *stream, URLSegment &seg)
 {
     nsresult rv;
 
@@ -3622,18 +3620,16 @@ nsStandardURL::GetClassDescription(nsACS
     aClassDescription.SetIsVoid(true);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsStandardURL::GetClassID(nsCID * *aClassID)
 {
     *aClassID = (nsCID*) moz_xmalloc(sizeof(nsCID));
-    if (!*aClassID)
-        return NS_ERROR_OUT_OF_MEMORY;
     return GetClassIDNoAlloc(*aClassID);
 }
 
 NS_IMETHODIMP
 nsStandardURL::GetFlags(uint32_t *aFlags)
 {
     *aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
     return NS_OK;
--- a/netwerk/cache/nsCacheEntryDescriptor.cpp
+++ b/netwerk/cache/nsCacheEntryDescriptor.cpp
@@ -1328,20 +1328,16 @@ nsCompressOutputStreamWrapper::Write(con
     }
 
     if (!mWriteBuffer) {
         // Once allocated, this buffer is referenced by the zlib stream and
         // cannot be grown. We use 2x(initial write request) to approximate
         // a stream buffer size proportional to request buffers.
         mWriteBufferLen = std::max(count*2, (uint32_t)kMinCompressWriteBufLen);
         mWriteBuffer = (unsigned char*)moz_xmalloc(mWriteBufferLen);
-        if (!mWriteBuffer) {
-            mWriteBufferLen = 0;
-            return NS_ERROR_OUT_OF_MEMORY;
-        }
         mZstream.next_out = mWriteBuffer;
         mZstream.avail_out = mWriteBufferLen;
     }
 
     // Compress (deflate) the requested buffer. Keep going
     // until the entire buffer has been deflated.
     mZstream.avail_in = count;
     mZstream.next_in = (Bytef*)buf;
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -2337,17 +2337,16 @@ nsOfflineCacheDevice::RunSimpleQuery(moz
       nsDependentCString(statement->AsSharedUTF8String(resultIndex, &length)));
 
     rv = statement->ExecuteStep(&hasRows);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   *count = valArray.Length();
   char **ret = static_cast<char **>(moz_xmalloc(*count * sizeof(char*)));
-  if (!ret) return NS_ERROR_OUT_OF_MEMORY;
 
   for (uint32_t i = 0; i <  *count; i++) {
     ret[i] = NS_strdup(valArray[i].get());
     if (!ret[i]) {
       NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, ret);
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
--- a/netwerk/mime/nsMIMEHeaderParamImpl.cpp
+++ b/netwerk/mime/nsMIMEHeaderParamImpl.cpp
@@ -226,41 +226,36 @@ char *combineContinuations(nsTArray<Cont
   for (uint32_t i = 0; i < aArray.Length(); i++) {
     length += aArray[i].length;
   }
 
   // Allocate
   char *result = (char *) moz_xmalloc(length + 1);
 
   // Concatenate
-  if (result) {
-    *result = '\0';
+  *result = '\0';
 
-    for (uint32_t i = 0; i < aArray.Length(); i++) {
-      Continuation cont = aArray[i];
-      if (! cont.value) break;
+  for (uint32_t i = 0; i < aArray.Length(); i++) {
+    Continuation cont = aArray[i];
+    if (! cont.value) break;
 
-      char *c = result + strlen(result);
-      strncat(result, cont.value, cont.length);
-      if (cont.needsPercentDecoding) {
-        nsUnescape(c);
-      }
-      if (cont.wasQuotedString) {
-        RemoveQuotedStringEscapes(c);
-      }
+    char *c = result + strlen(result);
+    strncat(result, cont.value, cont.length);
+    if (cont.needsPercentDecoding) {
+      nsUnescape(c);
     }
+    if (cont.wasQuotedString) {
+      RemoveQuotedStringEscapes(c);
+    }
+  }
 
-    // return null if empty value
-    if (*result == '\0') {
-      free(result);
-      result = nullptr;
-    }
-  } else {
-    // Handle OOM
-    NS_WARNING("Out of memory\n");
+  // return null if empty value
+  if (*result == '\0') {
+    free(result);
+    result = nullptr;
   }
 
   return result;
 }
 
 // add a continuation, return false on error if segment already has been seen
 bool addContinuation(nsTArray<Continuation>& aArray, uint32_t aIndex,
                      const char *aValue, uint32_t aLength,
@@ -810,19 +805,16 @@ bool IsRFC5987AttrChar(char aChar)
           c == '_' || c == '`' || c == '|' || c == '~');
 }
 
 // percent-decode a value
 // returns false on failure
 bool PercentDecode(nsACString& aValue)
 {
   char *c = (char *) moz_xmalloc(aValue.Length() + 1);
-  if (!c) {
-    return false;
-  }
 
   strcpy(c, PromiseFlatCString(aValue).get());
   nsUnescape(c);
   aValue.Assign(c);
   free(c);
 
   return true;
 }
--- a/security/manager/ssl/OSKeyStore.cpp
+++ b/security/manager/ssl/OSKeyStore.cpp
@@ -196,19 +196,16 @@ OSKeyStore::DecryptBytes(const nsACStrin
   std::vector<uint8_t> plaintextBytes;
   rv = mKs->EncryptDecrypt(
     label, ciphertextBytes, plaintextBytes, Cipher::Decrypt);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   *outBytes = (uint8_t*)moz_xmalloc(plaintextBytes.size());
-  if (!*outBytes) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
   memcpy(*outBytes, plaintextBytes.data(), plaintextBytes.size());
   *outLen = plaintextBytes.size();
   return NS_OK;
 }
 
 nsresult
 OSKeyStore::Lock()
 {
--- a/security/manager/ssl/TransportSecurityInfo.cpp
+++ b/security/manager/ssl/TransportSecurityInfo.cpp
@@ -338,18 +338,16 @@ TransportSecurityInfo::GetClassDescripti
   aClassDescription.SetIsVoid(true);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TransportSecurityInfo::GetClassID(nsCID * *aClassID)
 {
   *aClassID = (nsCID*) moz_xmalloc(sizeof(nsCID));
-  if (!*aClassID)
-    return NS_ERROR_OUT_OF_MEMORY;
   return GetClassIDNoAlloc(*aClassID);
 }
 
 NS_IMETHODIMP
 TransportSecurityInfo::GetFlags(uint32_t *aFlags)
 {
   *aFlags = 0;
   return NS_OK;
--- a/security/manager/ssl/nsKeygenHandler.cpp
+++ b/security/manager/ssl/nsKeygenHandler.cpp
@@ -322,20 +322,16 @@ GetSlotWithMechanism(uint32_t aMechanism
         tmpSlot = slotList->head;
         while (tmpSlot) {
             numSlots++;
             tmpSlot = tmpSlot->next;
         }
 
         // Allocate the slot name buffer //
         tokenNameList = static_cast<char16_t**>(moz_xmalloc(sizeof(char16_t *) * numSlots));
-        if (!tokenNameList) {
-            rv = NS_ERROR_OUT_OF_MEMORY;
-            goto loser;
-        }
 
         i = 0;
         slotElement = PK11_GetFirstSafe(slotList);
         while (slotElement) {
             tokenNameList[i] = UTF8ToNewUnicode(nsDependentCString(PK11_GetTokenName(slotElement->slot)));
             slotElement = PK11_GetNextSafe(slotList, slotElement, false);
             if (tokenNameList[i])
                 i++;
--- a/security/manager/ssl/nsNSSCertificate.cpp
+++ b/security/manager/ssl/nsNSSCertificate.cpp
@@ -384,19 +384,16 @@ nsNSSCertificate::GetEmailAddresses(uint
 
   for (const char* aAddr = CERT_GetFirstEmailAddress(mCert.get());
        aAddr;
        aAddr = CERT_GetNextEmailAddress(mCert.get(), aAddr)) {
     ++(*aLength);
   }
 
   *aAddresses = (char16_t**) moz_xmalloc(sizeof(char16_t*) * (*aLength));
-  if (!*aAddresses) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   uint32_t iAddr = 0;
   for (const char* aAddr = CERT_GetFirstEmailAddress(mCert.get());
        aAddr;
        aAddr = CERT_GetNextEmailAddress(mCert.get(), aAddr)) {
     (*aAddresses)[iAddr] = ToNewUnicode(nsDependentCString(aAddr));
     iAddr++;
   }
@@ -710,21 +707,19 @@ nsNSSCertificate::GetSha256SubjectPublic
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNSSCertificate::GetRawDER(uint32_t* aLength, uint8_t** aArray)
 {
   if (mCert) {
     *aArray = (uint8_t*)moz_xmalloc(mCert->derCert.len);
-    if (*aArray) {
-      memcpy(*aArray, mCert->derCert.data, mCert->derCert.len);
-      *aLength = mCert->derCert.len;
-      return NS_OK;
-    }
+    memcpy(*aArray, mCert->derCert.data, mCert->derCert.len);
+    *aLength = mCert->derCert.len;
+    return NS_OK;
   }
   *aLength = 0;
   return NS_ERROR_FAILURE;
 }
 
 CERTCertificate*
 nsNSSCertificate::GetCert()
 {
@@ -1332,18 +1327,16 @@ nsNSSCertificate::GetClassDescription(ns
   aClassDescription.SetIsVoid(true);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNSSCertificate::GetClassID(nsCID** aClassID)
 {
   *aClassID = (nsCID*) moz_xmalloc(sizeof(nsCID));
-  if (!*aClassID)
-    return NS_ERROR_OUT_OF_MEMORY;
   return GetClassIDNoAlloc(*aClassID);
 }
 
 NS_IMETHODIMP
 nsNSSCertificate::GetFlags(uint32_t* aFlags)
 {
   *aFlags = nsIClassInfo::THREADSAFE;
   return NS_OK;
--- a/security/manager/ssl/nsNTLMAuthModule.cpp
+++ b/security/manager/ssl/nsNTLMAuthModule.cpp
@@ -390,18 +390,16 @@ LM_Response(const uint8_t *hash, const u
 static nsresult
 GenerateType1Msg(void **outBuf, uint32_t *outLen)
 {
   //
   // verify that bufLen is sufficient
   //
   *outLen = NTLM_TYPE1_HEADER_LEN;
   *outBuf = moz_xmalloc(*outLen);
-  if (!*outBuf)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   //
   // write out type 1 msg
   //
   void *cursor = *outBuf;
 
   // 0 : signature
   cursor = WriteBytes(cursor, NTLM_SIGNATURE, sizeof(NTLM_SIGNATURE));
@@ -873,19 +871,16 @@ GenerateType3Msg(const nsString &domain,
   totalLen += ntlmRespLen.value();
 
   if (!totalLen.isValid()) {
     NS_ERROR("failed preparing to allocate NTLM response: integer overflow?!?");
     return NS_ERROR_FAILURE;
   }
   *outBuf = moz_xmalloc(totalLen.value());
   *outLen = totalLen.value();
-  if (!*outBuf) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   //
   // finally, we assemble the Type-3 msg :-)
   //
   void *cursor = *outBuf;
   mozilla::CheckedInt<uint32_t> offset;
 
   // 0 : signature
--- a/security/manager/ssl/nsRandomGenerator.cpp
+++ b/security/manager/ssl/nsRandomGenerator.cpp
@@ -20,19 +20,16 @@ nsRandomGenerator::GenerateRandomBytes(u
   *aBuffer = nullptr;
 
   mozilla::UniquePK11SlotInfo slot(PK11_GetInternalSlot());
   if (!slot) {
     return NS_ERROR_FAILURE;
   }
 
   auto buf = static_cast<uint8_t*>(moz_xmalloc(aLength));
-  if (!buf) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   SECStatus srv = PK11_GenerateRandomOnSlot(slot.get(), buf, aLength);
   if (srv != SECSuccess) {
     free(buf);
     return NS_ERROR_FAILURE;
   }
 
   *aBuffer = buf;
--- a/security/manager/ssl/nsSSLStatus.cpp
+++ b/security/manager/ssl/nsSSLStatus.cpp
@@ -340,19 +340,16 @@ nsSSLStatus::GetClassDescription(nsACStr
   aClassDescription.SetIsVoid(true);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSSLStatus::GetClassID(nsCID** aClassID)
 {
   *aClassID = (nsCID*) moz_xmalloc(sizeof(nsCID));
-  if (!*aClassID) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
   return GetClassIDNoAlloc(*aClassID);
 }
 
 NS_IMETHODIMP
 nsSSLStatus::GetFlags(uint32_t* aFlags)
 {
   *aFlags = 0;
   return NS_OK;
--- a/toolkit/components/places/nsAnnotationService.cpp
+++ b/toolkit/components/places/nsAnnotationService.cpp
@@ -449,17 +449,16 @@ nsAnnotationService::GetItemAnnotationNa
   nsresult rv = GetItemAnnotationNamesTArray(aItemId, &names);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (names.Length() == 0)
     return NS_OK;
 
   *_result = static_cast<nsIVariant**>
                         (moz_xmalloc(sizeof(nsIVariant*) * names.Length()));
-  NS_ENSURE_TRUE(*_result, NS_ERROR_OUT_OF_MEMORY);
 
   for (uint32_t i = 0; i < names.Length(); i ++) {
     nsCOMPtr<nsIWritableVariant> var = new nsVariant();
     if (!var) {
       // need to release all the variants we've already created
       for (uint32_t j = 0; j < i; j ++)
         NS_RELEASE((*_result)[j]);
       free(*_result);
--- a/toolkit/components/places/nsFaviconService.cpp
+++ b/toolkit/components/places/nsFaviconService.cpp
@@ -560,18 +560,16 @@ nsFaviconService::ReplaceFaviconDataFrom
   NS_ENSURE_SUCCESS(rv, rv);
   if (available64 == 0 || available64 > UINT32_MAX / sizeof(uint8_t))
     return NS_ERROR_FILE_TOO_BIG;
   uint32_t available = (uint32_t)available64;
 
   // Read all the decoded data.
   uint8_t* buffer = static_cast<uint8_t*>
                                (moz_xmalloc(sizeof(uint8_t) * available));
-  if (!buffer)
-    return NS_ERROR_OUT_OF_MEMORY;
   uint32_t numRead;
   rv = stream->Read(TO_CHARBUFFER(buffer), available, &numRead);
   if (NS_FAILED(rv) || numRead != available) {
     free(buffer);
     return rv;
   }
 
   nsAutoCString mimeType;
--- a/toolkit/components/places/nsNavHistoryQuery.cpp
+++ b/toolkit/components/places/nsNavHistoryQuery.cpp
@@ -825,18 +825,16 @@ NS_IMETHODIMP nsNavHistoryQuery::GetTags
 
   nsresult rv;
   if (arrayLen == 0)
     rv = out->SetAsEmptyArray();
   else {
     // Note: The resulting nsIVariant dupes both the array and its elements.
     const char16_t **array = reinterpret_cast<const char16_t **>
                               (moz_xmalloc(arrayLen * sizeof(char16_t *)));
-    NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
-
     for (uint32_t i = 0; i < arrayLen; ++i) {
       array[i] = mTags[i].get();
     }
 
     rv = out->SetAsArray(nsIDataType::VTYPE_WCHAR_STR,
                          nullptr,
                          arrayLen,
                          reinterpret_cast<void *>(array));
@@ -948,19 +946,17 @@ NS_IMETHODIMP nsNavHistoryQuery::SetTags
 }
 
 NS_IMETHODIMP nsNavHistoryQuery::GetParents(uint32_t *aGuidCount,
                                             char ***aGuids)
 {
   uint32_t count = mParents.Length();
   char **guids = nullptr;
   if (count > 0) {
-    guids = static_cast<char**>
-                       (moz_xmalloc(count * sizeof(char*)));
-    NS_ENSURE_TRUE(guids, NS_ERROR_OUT_OF_MEMORY);
+    guids = static_cast<char**>(moz_xmalloc(count * sizeof(char*)));
 
     for (uint32_t i = 0; i < count; ++i) {
       guids[i] = ToNewCString(mParents[i]);
     }
   }
   *aGuidCount = count;
   *aGuids = guids;
   return NS_OK;
@@ -988,17 +984,16 @@ NS_IMETHODIMP nsNavHistoryQuery::SetPare
 NS_IMETHODIMP nsNavHistoryQuery::GetTransitions(uint32_t* aCount,
                                                 uint32_t** aTransitions)
 {
   uint32_t count = mTransitions.Length();
   uint32_t* transitions = nullptr;
   if (count > 0) {
     transitions = reinterpret_cast<uint32_t*>
                   (moz_xmalloc(count * sizeof(uint32_t)));
-    NS_ENSURE_TRUE(transitions, NS_ERROR_OUT_OF_MEMORY);
     for (uint32_t i = 0; i < count; ++i) {
       transitions[i] = mTransitions[i];
     }
   }
   *aCount = count;
   *aTransitions = transitions;
   return NS_OK;
 }
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
@@ -225,17 +225,16 @@ nsUrlClassifierPrefixSet::GetPrefixes(ui
   FallibleTArray<uint32_t> prefixes;
   nsresult rv = GetPrefixesNative(prefixes);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   uint64_t itemCount = prefixes.Length();
   uint32_t* prefixArray = static_cast<uint32_t*>(moz_xmalloc(itemCount * sizeof(uint32_t)));
-  NS_ENSURE_TRUE(prefixArray, NS_ERROR_OUT_OF_MEMORY);
 
   memcpy(prefixArray, prefixes.Elements(), sizeof(uint32_t) * itemCount);
 
   *aCount = itemCount;
   *aPrefixes = prefixArray;
 
   return NS_OK;
 }
--- a/widget/GfxInfoBase.cpp
+++ b/widget/GfxInfoBase.cpp
@@ -1092,26 +1092,18 @@ NS_IMETHODIMP GfxInfoBase::GetFailures(u
   // and the strings in it should be small as well (the error messages in the
   // code.)  The second copy happens with the Clone() calls.  Technically,
   // we don't need the mutex lock after the StringVectorCopy() call.
   LoggingRecord loggedStrings = logForwarder->LoggingRecordCopy();
   *failureCount = loggedStrings.size();
 
   if (*failureCount != 0) {
     *failures = (char**)moz_xmalloc(*failureCount * sizeof(char*));
-    if (!(*failures)) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
     if (indices) {
       *indices = (int32_t*)moz_xmalloc(*failureCount * sizeof(int32_t));
-      if (!(*indices)) {
-        free(*failures);
-        *failures = nullptr;
-        return NS_ERROR_OUT_OF_MEMORY;
-      }
     }
 
     /* copy over the failure messages into the array we just allocated */
     LoggingRecord::const_iterator it;
     uint32_t i=0;
     for(it = loggedStrings.begin() ; it != loggedStrings.end(); ++it, i++) {
       (*failures)[i] = (char*)nsMemory::Clone(Get<1>(*it).c_str(), Get<1>(*it).size() + 1);
       if (indices) (*indices)[i] = Get<0>(*it);
--- a/widget/gtk/nsClipboard.cpp
+++ b/widget/gtk/nsClipboard.cpp
@@ -666,21 +666,19 @@ void ConvertHTMLtoUCS2(const char* data,
 {
     nsAutoCString charset;
     GetHTMLCharset(data, dataLength, charset);// get charset of HTML
     if (charset.EqualsLiteral("UTF-16")) {//current mozilla
         outUnicodeLen = (dataLength / 2) - 1;
         *unicodeData =
             reinterpret_cast<char16_t*>
             (moz_xmalloc((outUnicodeLen + sizeof('\0')) * sizeof(char16_t)));
-        if (*unicodeData) {
-            memcpy(*unicodeData, data + sizeof(char16_t),
-                   outUnicodeLen * sizeof(char16_t));
-            (*unicodeData)[outUnicodeLen] = '\0';
-        }
+        memcpy(*unicodeData, data + sizeof(char16_t),
+               outUnicodeLen * sizeof(char16_t));
+        (*unicodeData)[outUnicodeLen] = '\0';
     } else if (charset.EqualsLiteral("UNKNOWN")) {
         outUnicodeLen = 0;
         return;
     } else {
         // app which use "text/html" to copy&paste
         // get the decoder
         auto encoding = Encoding::ForLabelNoReplacement(charset);
         if (!encoding) {
@@ -696,37 +694,35 @@ void ConvertHTMLtoUCS2(const char* data,
           outUnicodeLen = 0;
           return;
         }
 
         outUnicodeLen = 0;
         if (needed.value()) {
           *unicodeData = reinterpret_cast<char16_t*>(
             moz_xmalloc((needed.value() + 1) * sizeof(char16_t)));
-          if (*unicodeData) {
-            uint32_t result;
-            size_t read;
-            size_t written;
-            bool hadErrors;
-            Tie(result, read, written, hadErrors) =
-              decoder->DecodeToUTF16(AsBytes(MakeSpan(data, dataLength)),
-                                     MakeSpan(*unicodeData, needed.value()),
-                                     true);
-            MOZ_ASSERT(result == kInputEmpty);
-            MOZ_ASSERT(read == size_t(dataLength));
-            MOZ_ASSERT(written <= needed.value());
-            Unused << hadErrors;
+          uint32_t result;
+          size_t read;
+          size_t written;
+          bool hadErrors;
+          Tie(result, read, written, hadErrors) =
+            decoder->DecodeToUTF16(AsBytes(MakeSpan(data, dataLength)),
+                                   MakeSpan(*unicodeData, needed.value()),
+                                   true);
+          MOZ_ASSERT(result == kInputEmpty);
+          MOZ_ASSERT(read == size_t(dataLength));
+          MOZ_ASSERT(written <= needed.value());
+          Unused << hadErrors;
 #ifdef DEBUG_CLIPBOARD
-            if (read != dataLength)
-              printf("didn't consume all the bytes\n");
+          if (read != dataLength)
+            printf("didn't consume all the bytes\n");
 #endif
-            outUnicodeLen = written;
-            // null terminate.
-            (*unicodeData)[outUnicodeLen] = '\0';
-            }
+          outUnicodeLen = written;
+          // null terminate.
+          (*unicodeData)[outUnicodeLen] = '\0';
         } // if valid length
     }
 }
 
 /*
  * get "charset" information from clipboard data
  * return value can be:
  *  1. "UTF-16":      mozilla or "text/html" with "charset=utf-16"
--- a/widget/nsPrimitiveHelpers.cpp
+++ b/widget/nsPrimitiveHelpers.cpp
@@ -99,18 +99,16 @@ nsPrimitiveHelpers :: CreatePrimitiveFor
   nsCOMPtr<nsISupportsString> primitive =
     do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
   if (!primitive)
     return;
 
   // We need to duplicate the input buffer, since the removal of linebreaks
   // might reallocte it.
   void* utf8 = moz_xmalloc(*aDataLen);
-  if (!utf8)
-    return;
   memcpy(utf8, aDataBuff, *aDataLen);
   int32_t signedLen = static_cast<int32_t>(*aDataLen);
   nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(nsDependentCString(kTextMime), &utf8, &signedLen);
   *aDataLen = signedLen;
 
   nsAutoString str(NS_ConvertUTF8toUTF16(reinterpret_cast<const char*>(utf8), *aDataLen));
   free(utf8);
   *aDataLen = str.Length() * sizeof(char16_t);
--- a/widget/windows/nsClipboard.cpp
+++ b/widget/windows/nsClipboard.cpp
@@ -503,25 +503,20 @@ nsresult nsClipboard::GetNativeDataOffCl
                 HDROP dropFiles = (HDROP) GlobalLock(stm.hGlobal);
 
                 UINT numFiles = ::DragQueryFileW(dropFiles, 0xFFFFFFFF, nullptr, 0);
                 NS_ASSERTION ( numFiles > 0, "File drop flavor, but no files...hmmmm" );
                 NS_ASSERTION ( aIndex < numFiles, "Asked for a file index out of range of list" );
                 if (numFiles > 0) {
                   UINT fileNameLen = ::DragQueryFileW(dropFiles, aIndex, nullptr, 0);
                   wchar_t* buffer = reinterpret_cast<wchar_t*>(moz_xmalloc((fileNameLen + 1) * sizeof(wchar_t)));
-                  if ( buffer ) {
-                    ::DragQueryFileW(dropFiles, aIndex, buffer, fileNameLen + 1);
-                    *aData = buffer;
-                    *aLen = fileNameLen * sizeof(char16_t);
-                    result = NS_OK;
-                  }
-                  else {
-                    result = NS_ERROR_OUT_OF_MEMORY;
-                  }
+                  ::DragQueryFileW(dropFiles, aIndex, buffer, fileNameLen + 1);
+                  *aData = buffer;
+                  *aLen = fileNameLen * sizeof(char16_t);
+                  result = NS_OK;
                 }
                 GlobalUnlock (stm.hGlobal) ;
 
               } break;
 
             default: {
               if ( fe.cfFormat == fileDescriptorFlavorA || fe.cfFormat == fileDescriptorFlavorW || fe.cfFormat == fileFlavor ) {
                 NS_WARNING ( "Mozilla doesn't yet understand how to read this type of file flavor" );
--- a/xpcom/base/nsCRTGlue.cpp
+++ b/xpcom/base/nsCRTGlue.cpp
@@ -127,35 +127,31 @@ NS_strdup(const char16_t* aString)
   return NS_strndup(aString, len);
 }
 
 template<typename CharT>
 CharT*
 NS_strndup(const CharT* aString, uint32_t aLen)
 {
   auto newBuf = (CharT*)moz_xmalloc((aLen + 1) * sizeof(CharT));
-  if (newBuf) {
-    memcpy(newBuf, aString, aLen * sizeof(CharT));
-    newBuf[aLen] = '\0';
-  }
+  memcpy(newBuf, aString, aLen * sizeof(CharT));
+  newBuf[aLen] = '\0';
   return newBuf;
 }
 
 template char16_t* NS_strndup<char16_t>(const char16_t* aString, uint32_t aLen);
 template char* NS_strndup<char>(const char* aString, uint32_t aLen);
 
 char*
 NS_strdup(const char* aString)
 {
   uint32_t len = strlen(aString);
   char* str = (char*)moz_xmalloc(len + 1);
-  if (str) {
-    memcpy(str, aString, len);
-    str[len] = '\0';
-  }
+  memcpy(str, aString, len);
+  str[len] = '\0';
   return str;
 }
 
 // This table maps uppercase characters to lower case characters;
 // characters that are neither upper nor lower case are unaffected.
 const unsigned char nsLowerUpperUtils::kUpper2Lower[256] = {
     0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
    16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
--- a/xpcom/base/nsCRTGlue.h
+++ b/xpcom/base/nsCRTGlue.h
@@ -48,29 +48,29 @@ uint32_t NS_strlen(const char16_t* aStri
 int NS_strcmp(const char16_t* aStrA, const char16_t* aStrB);
 
 /**
  * "strncmp" for char16_t strings
  */
 int NS_strncmp(const char16_t* aStrA, const char16_t* aStrB, size_t aLen);
 
 /**
- * "strdup" for char16_t strings, uses the moz_xmalloc allocator.
+ * "strdup" for char16_t strings, uses the infallible moz_xmalloc allocator.
  */
 char16_t* NS_strdup(const char16_t* aString);
 
 /**
- * "strdup", but using the moz_xmalloc allocator.
+ * "strdup", but using the infallible moz_xmalloc allocator.
  */
 char* NS_strdup(const char* aString);
 
 /**
  * strndup for char16_t or char strings (normal strndup is not available on
  * windows). This function will ensure that the new string is
- * null-terminated. Uses the moz_xmalloc allocator.
+ * null-terminated. Uses the infallible moz_xmalloc allocator.
  *
  * CharT may be either char16_t or char.
  */
 template<typename CharT>
 CharT* NS_strndup(const CharT* aString, uint32_t aLen);
 
 // The following case-conversion methods only deal in the ascii repertoire
 // A-Z and a-z
--- a/xpcom/base/nsID.cpp
+++ b/xpcom/base/nsID.cpp
@@ -102,24 +102,21 @@ static const char gIDFormat[] =
  * format. The string is allocated with moz_xmalloc and should be freed by
  * the caller.
  */
 
 char*
 nsID::ToString() const
 {
   char* res = (char*)moz_xmalloc(NSID_LENGTH);
-
-  if (res) {
-    snprintf(res, NSID_LENGTH, gIDFormat,
-             m0, (uint32_t)m1, (uint32_t)m2,
-             (uint32_t)m3[0], (uint32_t)m3[1], (uint32_t)m3[2],
-             (uint32_t)m3[3], (uint32_t)m3[4], (uint32_t)m3[5],
-             (uint32_t)m3[6], (uint32_t)m3[7]);
-  }
+  snprintf(res, NSID_LENGTH, gIDFormat,
+           m0, (uint32_t)m1, (uint32_t)m2,
+           (uint32_t)m3[0], (uint32_t)m3[1], (uint32_t)m3[2],
+           (uint32_t)m3[3], (uint32_t)m3[4], (uint32_t)m3[5],
+           (uint32_t)m3[6], (uint32_t)m3[7]);
   return res;
 }
 
 void
 nsID::ToProvidedString(char (&aDest)[NSID_LENGTH]) const
 {
   SprintfLiteral(aDest, gIDFormat,
                  m0, (uint32_t)m1, (uint32_t)m2,
--- a/xpcom/base/nsMemory.cpp
+++ b/xpcom/base/nsMemory.cpp
@@ -26,19 +26,17 @@ nsMemory::HeapMinimize(bool aImmediate)
 
   return mem->HeapMinimize(aImmediate);
 }
 
 void*
 nsMemory::Clone(const void* aPtr, size_t aSize)
 {
   void* newPtr = moz_xmalloc(aSize);
-  if (newPtr) {
-    memcpy(newPtr, aPtr, aSize);
-  }
+  memcpy(newPtr, aPtr, aSize);
   return newPtr;
 }
 
 nsIMemory*
 nsMemory::GetGlobalMemoryService()
 {
   nsIMemory* mem;
   nsresult rv = NS_GetMemoryManager(&mem);
--- a/xpcom/base/nsUUIDGenerator.cpp
+++ b/xpcom/base/nsUUIDGenerator.cpp
@@ -80,19 +80,16 @@ nsUUIDGenerator::Init()
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsUUIDGenerator::GenerateUUID(nsID** aRet)
 {
   nsID* id = static_cast<nsID*>(moz_xmalloc(sizeof(nsID)));
-  if (!id) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   nsresult rv = GenerateUUIDInPlace(id);
   if (NS_FAILED(rv)) {
     free(id);
     return rv;
   }
 
   *aRet = id;
--- a/xpcom/ds/nsVariant.cpp
+++ b/xpcom/ds/nsVariant.cpp
@@ -324,19 +324,16 @@ CloneArray(uint16_t aInType, const nsIID
       return NS_ERROR_CANNOT_CONVERT_DATA;
   }
 
 
   // Alloc the u.array.
 
   allocSize = aInCount * elementSize;
   *aOutValue = moz_xmalloc(allocSize);
-  if (!*aOutValue) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   // Clone the elements.
 
   switch (aInType) {
     case nsIDataType::VTYPE_INT8:
     case nsIDataType::VTYPE_INT16:
     case nsIDataType::VTYPE_INT32:
     case nsIDataType::VTYPE_INT64:
--- a/xpcom/io/nsEscape.cpp
+++ b/xpcom/io/nsEscape.cpp
@@ -108,19 +108,16 @@ nsEscape(const char* aStr, size_t aLengt
   }
 
   // fail if we need more than 4GB
   if (dstSize > UINT32_MAX) {
     return nullptr;
   }
 
   char* result = (char*)moz_xmalloc(dstSize);
-  if (!result) {
-    return nullptr;
-  }
 
   unsigned char* dst = (unsigned char*)result;
   src = (const unsigned char*)aStr;
   if (aFlags == url_XPAlphas) {
     for (size_t i = 0; i < aLength; ++i) {
       unsigned char c = *src++;
       if (IS_OK(c)) {
         *dst++ = c;
--- a/xpcom/io/nsSegmentedBuffer.cpp
+++ b/xpcom/io/nsSegmentedBuffer.cpp
@@ -28,19 +28,16 @@ nsSegmentedBuffer::AppendNewSegment()
 {
   if (GetSize() >= mMaxSize) {
     return nullptr;
   }
 
   if (!mSegmentArray) {
     uint32_t bytes = mSegmentArrayCount * sizeof(char*);
     mSegmentArray = (char**)moz_xmalloc(bytes);
-    if (!mSegmentArray) {
-      return nullptr;
-    }
     memset(mSegmentArray, 0, bytes);
   }
 
   if (IsFull()) {
     uint32_t newArraySize = mSegmentArrayCount * 2;
     uint32_t bytes = newArraySize * sizeof(char*);
     char** newSegArray = (char**)moz_xrealloc(mSegmentArray, bytes);
     if (!newSegArray) {
--- a/xpcom/io/nsWildCard.cpp
+++ b/xpcom/io/nsWildCard.cpp
@@ -236,19 +236,16 @@ static int
 
   /* Find the closing parenthesis that ends this union in the expression */
   cp = ::_scan_and_copy(aExpr, T(')'), T('\0'), static_cast<T*>(nullptr));
   if (cp == ABORTED || cp < 4) { /* must be at least "(a|b" before ')' */
     return ABORTED;
   }
   ++cp;                /* now index of char after closing parenthesis */
   e2 = (T*)moz_xmalloc((1 + nsCharTraits<T>::length(aExpr)) * sizeof(T));
-  if (!e2) {
-    return ABORTED;
-  }
   for (sx = 1; ; ++sx) {
     /* Here, aExpr[sx] is one character past the preceding '(' or '|'. */
     /* Copy everything up to the next delimiter to e2 */
     count = ::_scan_and_copy(aExpr + sx, T(')'), T('|'), e2);
     if (count == ABORTED || !count) {
       ret = ABORTED;
       break;
     }
@@ -421,19 +418,16 @@ ns_WildCardMatch(const T* aStr, const T*
   T* expr = nullptr;
   int ret = MATCH;
 
   if (!nsCharTraits<T>::find(aXp, nsCharTraits<T>::length(aXp), T('~'))) {
     return ::_shexp_match(aStr, aXp, aCaseInsensitive, 0);
   }
 
   expr = (T*)moz_xmalloc((nsCharTraits<T>::length(aXp) + 1) * sizeof(T));
-  if (!expr) {
-    return NOMATCH;
-  }
   memcpy(expr, aXp, (nsCharTraits<T>::length(aXp) + 1) * sizeof(T));
 
   int x = ::_scan_and_copy(expr, T('~'), T('\0'), static_cast<T*>(nullptr));
   if (x != ABORTED && expr[x] == '~') {
     expr[x++] = '\0';
     ret = ::_shexp_match(aStr, &expr[x], aCaseInsensitive, 0);
     switch (ret) {
       case NOMATCH:
--- a/xpcom/string/nsReadableUtils.cpp
+++ b/xpcom/string/nsReadableUtils.cpp
@@ -64,19 +64,16 @@ ToNewUTF8String(const nsAString& aSource
   mozilla::CheckedInt<uint32_t> destLen(len);
   destLen *= 3;
   destLen += 2;
   if (!destLen.isValid()) {
     return nullptr;
   }
   size_t destLenVal = destLen.value();
   char* dest = static_cast<char*>(moz_xmalloc(destLenVal));
-  if (!dest) {
-    return nullptr;
-  }
 
   size_t written = ConvertUTF16toUTF8(aSource, MakeSpan(dest, destLenVal));
   dest[written] = 0;
 
   if (aUTF8Count) {
     *aUTF8Count = written;
   }
 
@@ -141,19 +138,16 @@ UTF8ToNewUnicode(const nsACString& aSour
   // We need UTF-16 units
   allocLength *= sizeof(char16_t);
 
   if (!allocLength.isValid()) {
     return nullptr;
   }
 
   char16_t* dest = (char16_t*)moz_xmalloc(allocLength.value());
-  if (!dest) {
-    return nullptr;
-  }
 
   size_t written = ConvertUTF8toUTF16(aSource, MakeSpan(dest, lengthPlusOne));
   dest[written] = 0;
 
   if (aUTF16Count) {
     *aUTF16Count = written;
   }
 
--- a/xpcom/threads/nsProcessCommon.cpp
+++ b/xpcom/threads/nsProcessCommon.cpp
@@ -361,19 +361,16 @@ nsProcess::RunAsync(const char** aArgs, 
 nsresult
 nsProcess::CopyArgsAndRunProcess(bool aBlocking, const char** aArgs,
                                  uint32_t aCount, nsIObserver* aObserver,
                                  bool aHoldWeak)
 {
   // Add one to the aCount for the program name and one for null termination.
   char** my_argv = nullptr;
   my_argv = (char**)moz_xmalloc(sizeof(char*) * (aCount + 2));
-  if (!my_argv) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   my_argv[0] = ToNewUTF8String(mTargetPath);
 
   for (uint32_t i = 0; i < aCount; ++i) {
     my_argv[i + 1] = const_cast<char*>(aArgs[i]);
   }
 
   my_argv[aCount + 1] = nullptr;
@@ -403,19 +400,16 @@ nsProcess::RunwAsync(const char16_t** aA
 nsresult
 nsProcess::CopyArgsAndRunProcessw(bool aBlocking, const char16_t** aArgs,
                                   uint32_t aCount, nsIObserver* aObserver,
                                   bool aHoldWeak)
 {
   // Add one to the aCount for the program name and one for null termination.
   char** my_argv = nullptr;
   my_argv = (char**)moz_xmalloc(sizeof(char*) * (aCount + 2));
-  if (!my_argv) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
 
   my_argv[0] = ToNewUTF8String(mTargetPath);
 
   for (uint32_t i = 0; i < aCount; i++) {
     my_argv[i + 1] = ToNewUTF8String(nsDependentString(aArgs[i]));
   }
 
   my_argv[aCount + 1] = nullptr;