Bug 1408196 - Port bug 1407838 to C-C: Replace use of NS_Alloc/NS_Free. rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Fri, 13 Oct 2017 01:13:43 +0200
changeset 29170 7749bbeaf9b068e3291be3b35e3b1b7a893e3e89
parent 29169 e8fac029f7e443867fde96aa62c6a4d1057b46cf
child 29171 10d1c5b3288570adb3139c17d456fae16b7a0a57
push id2068
push userclokep@gmail.com
push dateMon, 13 Nov 2017 19:02:14 +0000
treeherdercomm-beta@9c7e7ce8672b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbustage-fix
bugs1408196, 1407838
Bug 1408196 - Port bug 1407838 to C-C: Replace use of NS_Alloc/NS_Free. rs=bustage-fix
ldap/xpcom/src/nsLDAPOperation.cpp
ldap/xpcom/src/nsLDAPService.cpp
mail/components/migration/src/nsMailProfileMigratorUtils.cpp
mail/components/migration/src/nsSeamonkeyProfileMigrator.cpp
mailnews/addrbook/src/nsAbOutlookDirectory.cpp
mailnews/addrbook/src/nsAbWinHelper.cpp
mailnews/base/search/src/nsMsgSearchAdapter.cpp
mailnews/base/search/src/nsMsgSearchTerm.cpp
mailnews/base/search/src/nsMsgSearchValue.cpp
mailnews/base/src/nsMessenger.cpp
mailnews/base/src/nsMessengerUnixIntegration.cpp
mailnews/base/src/nsMsgDBView.cpp
mailnews/base/src/nsMsgTagService.cpp
mailnews/base/src/nsSubscribableServer.cpp
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/compose/src/nsMsgCompFields.cpp
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/src/nsSmtpProtocol.cpp
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapProtocol.cpp
mailnews/imap/src/nsImapServerResponseParser.cpp
mailnews/imap/src/nsImapService.cpp
mailnews/imap/src/nsImapUrl.cpp
mailnews/import/outlook/src/MapiApi.cpp
mailnews/import/outlook/src/MapiMessage.cpp
mailnews/import/outlook/src/nsOutlookImport.cpp
mailnews/import/src/nsImportAddressBooks.cpp
mailnews/import/src/nsImportFieldMap.cpp
mailnews/import/src/nsImportMail.cpp
mailnews/import/text/src/nsTextImport.cpp
mailnews/import/vcard/src/nsVCardImport.cpp
mailnews/local/src/nsMsgMaildirStore.cpp
mailnews/mime/cthandlers/glue/nsMimeContentTypeHandler.cpp
mailnews/mime/emitters/nsMimeBaseEmitter.cpp
mailnews/mime/emitters/nsMimeXmlEmitter.cpp
mailnews/mime/src/mimemoz2.cpp
mailnews/mime/src/nsStreamConverter.cpp
suite/profile/migration/src/nsNetscapeProfileMigratorBase.cpp
--- a/ldap/xpcom/src/nsLDAPOperation.cpp
+++ b/ldap/xpcom/src/nsLDAPOperation.cpp
@@ -447,17 +447,17 @@ nsLDAPOperation::SearchExt(const nsACStr
     // Convert our comma separated string to one that the C-SDK will like, i.e.
     // convert to a char array and add a last NULL element.
     nsTArray<nsCString> attrArray;
     ParseString(aAttributes, ',', attrArray);
     char **attrs = nullptr;
     uint32_t origLength = attrArray.Length();
     if (origLength)
     {
-      attrs = static_cast<char **> (NS_Alloc((origLength + 1) * sizeof(char *)));
+      attrs = static_cast<char **> (moz_xmalloc((origLength + 1) * sizeof(char *)));
       if (!attrs)
         return NS_ERROR_OUT_OF_MEMORY;
 
       for (uint32_t i = 0; i < origLength; ++i)
         attrs[i] = ToNewCString(attrArray[i]);
 
       attrs[origLength] = 0;
     }
--- a/ldap/xpcom/src/nsLDAPService.cpp
+++ b/ldap/xpcom/src/nsLDAPService.cpp
@@ -885,17 +885,17 @@ NS_IMETHODIMP nsLDAPService::ParseDn(con
             ++len;
         if (*p != '=') {
             NS_ERROR("nsLDAPService::parseDn: "
                 "could not find '=' in RDN component");
             ldap_value_free(dnComponents);
             ldap_value_free(rdnComponents);
             return NS_ERROR_UNEXPECTED;
         }
-        if (!(attrNameArray[index] = (char*)NS_Alloc(len + 1))) {
+        if (!(attrNameArray[index] = (char*)moz_xmalloc(len + 1))) {
             NS_ERROR("nsLDAPService::ParseDn: out of memory ");
             ldap_value_free(dnComponents);
             ldap_value_free(rdnComponents);
             NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(index, attrNameArray);
             return NS_ERROR_OUT_OF_MEMORY;
         }
         memcpy(attrNameArray[index], *component, len);
         *(attrNameArray[index] + len) = '\0';
--- a/mail/components/migration/src/nsMailProfileMigratorUtils.cpp
+++ b/mail/components/migration/src/nsMailProfileMigratorUtils.cpp
@@ -67,17 +67,17 @@ void GetMigrateDataFromArray(MigrationDa
     // can be imported.
     if (aReplace || !cursor->replaceOnly) {
       aSourceProfile->Clone(getter_AddRefs(sourceFile));
       sourceFile->Append(nsDependentString(cursor->fileName));
       sourceFile->Exists(&exists);
       if (exists)
         *aResult |= cursor->sourceFlag;
     }
-    NS_Free(cursor->fileName);
+    free(cursor->fileName);
     cursor->fileName = nullptr;
   }
 }
 
 void
 GetProfilePath(nsIProfileStartup* aStartup, nsCOMPtr<nsIFile>& aProfileDir)
 {
   if (aStartup) {
--- a/mail/components/migration/src/nsSeamonkeyProfileMigrator.cpp
+++ b/mail/components/migration/src/nsSeamonkeyProfileMigrator.cpp
@@ -445,17 +445,17 @@ nsSeamonkeyProfileMigrator::CopySignatur
         srcSigFile->GetLeafName(leafName);
         srcSigFile->CopyTo(targetSigFile,leafName); // will fail if we've already copied a sig file here
         targetSigFile->Append(leafName);
 
         // now write out the new descriptor
         nsAutoCString descriptorString;
         rv = targetSigFile->GetPersistentDescriptor(descriptorString);
         NS_ENSURE_SUCCESS(rv, rv);
-        NS_Free(pref->stringValue);
+        free(pref->stringValue);
         pref->stringValue = ToNewCString(descriptorString);
       }
     }
   }
   return NS_OK;
 }
 
 nsresult
@@ -476,17 +476,17 @@ nsSeamonkeyProfileMigrator::CopyMailFold
 
     if (StringEndsWith(prefName, NS_LITERAL_CSTRING(".directory-rel"))) {
       // When the directories are modified below, we may change the .directory
       // pref. As we don't have a pref branch to modify at this stage and set
       // up the relative folders properly, we'll just remove all the
       // *.directory-rel prefs. Mailnews will cope with this, creating them
       // when it first needs them.
       if (pref->type == nsIPrefBranch::PREF_STRING)
-        NS_Free(pref->stringValue);
+        free(pref->stringValue);
 
       aMailServers.RemoveElementAt(i);
       // Now decrease i and count to match the removed element
       --i;
       --count;
     }
     else if (StringEndsWith(prefName, nsDependentCString(".directory")))
     {
@@ -540,17 +540,17 @@ nsSeamonkeyProfileMigrator::CopyMailFold
 
         (void) RecursiveCopy(sourceMailFolder, targetMailFolder);
         // now we want to make sure the actual directory pref that gets
         // transformed into the new profile's pref.js has the right file
         // location.
         nsAutoCString descriptorString;
         rv = targetMailFolder->GetPersistentDescriptor(descriptorString);
         NS_ENSURE_SUCCESS(rv, rv);
-        NS_Free(pref->stringValue);
+        free(pref->stringValue);
         pref->stringValue = ToNewCString(descriptorString);
       }
     }
     else if (StringEndsWith(prefName, nsDependentCString(".newsrc.file")))
     {
       // copy the news RC file into \News. this won't work if the user has different newsrc files for each account
       // I don't know what to do in that situation.
 
@@ -572,17 +572,17 @@ nsSeamonkeyProfileMigrator::CopyMailFold
         srcNewsRCFile->GetLeafName(leafName);
         srcNewsRCFile->CopyTo(targetNewsRCFile,leafName); // will fail if we've already copied a newsrc file here
         targetNewsRCFile->Append(leafName);
 
         // now write out the new descriptor
         nsAutoCString descriptorString;
         rv = targetNewsRCFile->GetPersistentDescriptor(descriptorString);
         NS_ENSURE_SUCCESS(rv, rv);
-        NS_Free(pref->stringValue);
+        free(pref->stringValue);
         pref->stringValue = ToNewCString(descriptorString);
       }
     }
   }
 
   return NS_OK;
 }
 
@@ -686,31 +686,31 @@ nsSeamonkeyProfileMigrator::WriteBranch(
   aPrefService->GetBranch(branchName, getter_AddRefs(branch));
 
   uint32_t count = aPrefs.Length();
   for (uint32_t i = 0; i < count; ++i) {
     PrefBranchStruct* pref = aPrefs.ElementAt(i);
     switch (pref->type) {
     case nsIPrefBranch::PREF_STRING:
       (void) branch->SetCharPref(pref->prefName, pref->stringValue);
-      NS_Free(pref->stringValue);
+      free(pref->stringValue);
       pref->stringValue = nullptr;
       break;
     case nsIPrefBranch::PREF_BOOL:
       (void) branch->SetBoolPref(pref->prefName, pref->boolValue);
       break;
     case nsIPrefBranch::PREF_INT:
       (void) branch->SetIntPref(pref->prefName, pref->intValue);
       break;
     default:
       NS_WARNING("Invalid Pref Type in "
                  "nsNetscapeProfileMigratorBase::WriteBranch\n");
       break;
     }
-    NS_Free(pref->prefName);
+    free(pref->prefName);
     pref->prefName = nullptr;
     delete pref;
     pref = nullptr;
   }
   aPrefs.Clear();
 }
 
 nsresult nsSeamonkeyProfileMigrator::DummyCopyRoutine(bool aReplace)
--- a/mailnews/addrbook/src/nsAbOutlookDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbOutlookDirectory.cpp
@@ -797,38 +797,38 @@ static void DestroyRestriction(SRestrict
             }
             delete [] aRestriction.res.resAnd.lpRes ;
         }
         break ;
     case RES_COMMENT :
         break ;
     case RES_CONTENT :
         if (PROP_TYPE(aRestriction.res.resContent.ulPropTag) == PT_UNICODE) {
-            NS_Free(aRestriction.res.resContent.lpProp->Value.lpszW) ;
+            free(aRestriction.res.resContent.lpProp->Value.lpszW) ;
         }
         else if (PROP_TYPE(aRestriction.res.resContent.ulPropTag) == PT_STRING8) {
-            NS_Free(aRestriction.res.resContent.lpProp->Value.lpszA) ;
+            free(aRestriction.res.resContent.lpProp->Value.lpszA) ;
         }
         delete aRestriction.res.resContent.lpProp ;
         break ;
     case RES_EXIST :
         break ;
     case RES_NOT :
         DestroyRestriction(*aRestriction.res.resNot.lpRes) ;
         delete aRestriction.res.resNot.lpRes ;
         break ;
     case RES_BITMASK :
     case RES_COMPAREPROPS :
         break ;
     case RES_PROPERTY :
         if (PROP_TYPE(aRestriction.res.resProperty.ulPropTag) == PT_UNICODE) {
-            NS_Free(aRestriction.res.resProperty.lpProp->Value.lpszW) ;
+            free(aRestriction.res.resProperty.lpProp->Value.lpszW) ;
         }
         else if (PROP_TYPE(aRestriction.res.resProperty.ulPropTag) == PT_STRING8) {
-            NS_Free(aRestriction.res.resProperty.lpProp->Value.lpszA) ;
+            free(aRestriction.res.resProperty.lpProp->Value.lpszA) ;
         }
         delete aRestriction.res.resProperty.lpProp ;
     case RES_SIZE :
     case RES_SUBRESTRICTION :
         break ;
     }
 }
 
--- a/mailnews/addrbook/src/nsAbWinHelper.cpp
+++ b/mailnews/addrbook/src/nsAbWinHelper.cpp
@@ -554,17 +554,17 @@ BOOL nsAbWinHelper::SetPropertiesUString
             }
             values [currentValue ++].Value.lpszA = av ;
         }
     }
     if (retCode)
         retCode = SetMAPIProperties(aObject, currentValue, values) ;
     for (i = 0 ; i < currentValue ; ++ i) {
         if (PROP_TYPE(aPropertiesTag [i]) == PT_STRING8) {
-            NS_Free(values [i].Value.lpszA) ;
+            free(values [i].Value.lpszA) ;
         }
     }
     delete [] values ;
     return retCode ;
 }
 
 BOOL nsAbWinHelper::SetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag, 
                                     WORD aYear, WORD aMonth, WORD aDay)
--- a/mailnews/base/search/src/nsMsgSearchAdapter.cpp
+++ b/mailnews/base/search/src/nsMsgSearchAdapter.cpp
@@ -569,17 +569,17 @@ nsresult nsMsgSearchAdapter::EncodeImapT
               *p++ = ch;
             }
             *p = '\0';
             value = strdup(newValue.get()); // realloc down to smaller size
           }
         }
         else
           value = strdup("");
-        NS_Free(convertedValue);
+        free(convertedValue);
         valueWasAllocated = true;
 
       }
     }
 
     // this should be rewritten to use nsCString
     int subLen =
       (value ? strlen(value) : 0) +
@@ -619,17 +619,17 @@ nsresult nsMsgSearchAdapter::EncodeImapT
 
       // kmcentee, don't let the encoding end with whitespace,
       // this throws off later url STRCMP
       if (*encoding && *(encoding + strlen(encoding) - 1) == ' ')
         *(encoding + strlen(encoding) - 1) = '\0';
     }
 
     if (value && valueWasAllocated)
-      NS_Free (value);
+      free (value);
 
     *ppOutTerm = encoding;
 
     return err;
 }
 
 nsresult nsMsgSearchAdapter::EncodeImapValue(char *encoding, const char *value, bool useQuotes, bool reallyDredd)
 {
--- a/mailnews/base/search/src/nsMsgSearchTerm.cpp
+++ b/mailnews/base/search/src/nsMsgSearchTerm.cpp
@@ -396,17 +396,17 @@ nsMsgSearchTerm::nsMsgSearchTerm (
   m_matchAll = false;
 }
 
 
 
 nsMsgSearchTerm::~nsMsgSearchTerm ()
 {
   if (IS_STRING_ATTRIBUTE (m_attribute) && m_value.string)
-    NS_Free(m_value.string);
+    free(m_value.string);
 }
 
 NS_IMPL_ISUPPORTS(nsMsgSearchTerm, nsIMsgSearchTerm)
 
 
 // Perhaps we could find a better place for this?
 // Caller needs to free.
 /* static */char *nsMsgSearchTerm::EscapeQuotesInStr(const char *str)
--- a/mailnews/base/search/src/nsMsgSearchValue.cpp
+++ b/mailnews/base/search/src/nsMsgSearchValue.cpp
@@ -19,17 +19,17 @@ nsMsgSearchValueImpl::nsMsgSearchValueIm
     }
     else
         mValue.string = 0;
 }
 
 nsMsgSearchValueImpl::~nsMsgSearchValueImpl()
 {
   if (IS_STRING_ATTRIBUTE(mValue.attribute))
-    NS_Free(mValue.string);
+    free(mValue.string);
 }
 
 NS_IMPL_ISUPPORTS(nsMsgSearchValueImpl, nsIMsgSearchValue)
 
 NS_IMPL_GETSET(nsMsgSearchValueImpl, Priority, nsMsgPriorityValue, mValue.u.priority)
 NS_IMPL_GETSET(nsMsgSearchValueImpl, Status, uint32_t, mValue.u.msgStatus)
 NS_IMPL_GETSET(nsMsgSearchValueImpl, Size, uint32_t, mValue.u.size)
 NS_IMPL_GETSET(nsMsgSearchValueImpl, MsgKey, nsMsgKey, mValue.u.key)
@@ -65,17 +65,17 @@ nsMsgSearchValueImpl::GetStr(nsAString &
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgSearchValueImpl::SetStr(const nsAString &aValue)
 {
     NS_ENSURE_TRUE(IS_STRING_ATTRIBUTE(mValue.attribute), NS_ERROR_ILLEGAL_VALUE);
     if (mValue.string)
-        NS_Free(mValue.string);
+        free(mValue.string);
     mValue.string = ToNewUTF8String(aValue);
     mValue.utf16String = aValue;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgSearchValueImpl::ToString(nsAString &aResult)
 {
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -2088,26 +2088,26 @@ nsSaveAllAttachmentsState::nsSaveAllAtta
     m_detachingAttachments = detachingAttachments;
 }
 
 nsSaveAllAttachmentsState::~nsSaveAllAttachmentsState()
 {
     uint32_t i;
     for (i = 0; i < m_count; i++)
     {
-      NS_Free(m_contentTypeArray[i]);
-      NS_Free(m_urlArray[i]);
-      NS_Free(m_displayNameArray[i]);
-      NS_Free(m_messageUriArray[i]);
+      free(m_contentTypeArray[i]);
+      free(m_urlArray[i]);
+      free(m_displayNameArray[i]);
+      free(m_messageUriArray[i]);
     }
     delete[] m_contentTypeArray;
     delete[] m_urlArray;
     delete[] m_displayNameArray;
     delete[] m_messageUriArray;
-    NS_Free(m_directoryName);
+    free(m_directoryName);
 }
 
 nsresult
 nsMessenger::GetLastSaveDirectory(nsIFile **aLastSaveDir)
 {
   nsresult rv;
   nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv,rv);
@@ -2383,20 +2383,20 @@ struct msgAttachment
 
   ~msgAttachment()
   {
     Clear();
   }
 
   void Clear()
   {
-    NS_Free(mContentType);
-    NS_Free(mUrl);
-    NS_Free(mDisplayName);
-    NS_Free(mMessageUri);
+    free(mContentType);
+    free(mUrl);
+    free(mDisplayName);
+    free(mMessageUri);
   }
 
   bool Init(const char * aContentType, const char * aUrl,
               const char * aDisplayName, const char * aMessageUri)
   {
     Clear();
     mContentType = strdup(aContentType);
     mUrl = strdup(aUrl);
--- a/mailnews/base/src/nsMessengerUnixIntegration.cpp
+++ b/mailnews/base/src/nsMessengerUnixIntegration.cpp
@@ -489,17 +489,17 @@ void nsMessengerUnixIntegration::FillToo
 
     uint32_t numNewKeys = 0;
     uint32_t *newMessageKeys;
     db->GetNewList(&numNewKeys, &newMessageKeys);
 
     // If we had new messages, we *should* have new keys, but we'll
     // check just in case.
     if (numNewKeys <= 0) {
-      NS_Free(newMessageKeys);
+      free(newMessageKeys);
       return;
     }
 
     // Find the rootFolder that folder belongs to, and find out
     // what MRUTime it maps to.  Assign this to lastMRUTime.
     uint32_t lastMRUTime = 0;
     if (NS_FAILED(GetMRUTimestampForFolder(folder, &lastMRUTime)))
       lastMRUTime = 0;
@@ -517,17 +517,17 @@ void nsMessengerUnixIntegration::FillToo
 
       if (dateInSeconds > lastMRUTime)
         newMsgHdrs.AppendObject(hdr);
 
     }
 
     // At this point, we don't need newMessageKeys any more,
     // so let's free it.
-    NS_Free(newMessageKeys);
+    free(newMessageKeys);
 
     // If we didn't happen to add any message headers, bail out
     if (!newMsgHdrs.Count())
       return;
 
     // Sort the message headers by dateInSeconds, in ascending
     // order
     newMsgHdrs.Sort(nsMsgDbHdrTimestampComparator, nullptr);
--- a/mailnews/base/src/nsMsgDBView.cpp
+++ b/mailnews/base/src/nsMsgDBView.cpp
@@ -168,26 +168,26 @@ nsMsgDBView::InitializeLiterals()
 nsMsgDBView::~nsMsgDBView()
 {
   if (m_db)
     m_db->RemoveListener(this);
 
   gInstanceCount--;
   if (gInstanceCount <= 0)
   {
-    NS_Free(kHighestPriorityString);
-    NS_Free(kHighPriorityString);
-    NS_Free(kLowestPriorityString);
-    NS_Free(kLowPriorityString);
-    NS_Free(kNormalPriorityString);
-
-    NS_Free(kReadString);
-    NS_Free(kRepliedString);
-    NS_Free(kForwardedString);
-    NS_Free(kNewString);
+    free(kHighestPriorityString);
+    free(kHighPriorityString);
+    free(kLowestPriorityString);
+    free(kLowPriorityString);
+    free(kNormalPriorityString);
+
+    free(kReadString);
+    free(kRepliedString);
+    free(kForwardedString);
+    free(kNewString);
   }
 }
 
 nsresult
 nsMsgDBView::InitLabelStrings()
 {
   nsresult rv = NS_OK;
   nsCString prefString;
@@ -2685,17 +2685,17 @@ nsMsgDBView::GetIndicesForSelection(uint
   nsMsgViewIndexArray selection;
   GetSelectedIndices(selection);
   uint32_t numIndices = selection.Length();
   if (!numIndices)
     return NS_OK;
 
   *length = numIndices;
   uint32_t datalen = numIndices * sizeof(nsMsgViewIndex);
-  *indices = (nsMsgViewIndex *)NS_Alloc(datalen);
+  *indices = (nsMsgViewIndex *)moz_xmalloc(datalen);
   if (!*indices)
     return NS_ERROR_OUT_OF_MEMORY;
 
   memcpy(*indices, selection.Elements(), datalen);
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -2719,17 +2719,17 @@ nsMsgDBView::GetSelectedMsgHdrs(uint32_t
   nsCOMPtr<nsIMutableArray> messages(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
   rv = GetHeadersFromSelection(selection.Elements(), numIndices, messages);
   NS_ENSURE_SUCCESS(rv, rv);
   uint32_t numMsgsSelected;
   messages->GetLength(&numMsgsSelected);
 
   nsIMsgDBHdr **headers =
-    static_cast<nsIMsgDBHdr**>(NS_Alloc(sizeof(nsIMsgDBHdr*) * numMsgsSelected));
+    static_cast<nsIMsgDBHdr**>(moz_xmalloc(sizeof(nsIMsgDBHdr*) * numMsgsSelected));
 
   for (uint32_t i = 0; i < numMsgsSelected; i++)
   {
     nsCOMPtr<nsIMsgDBHdr> msgHdr = do_QueryElementAt(messages, i, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
     // Already AddRefed.
     msgHdr.forget(&headers[i]);
   }
--- a/mailnews/base/src/nsMsgTagService.cpp
+++ b/mailnews/base/src/nsMsgTagService.cpp
@@ -353,17 +353,17 @@ NS_IMETHODIMP nsMsgTagService::GetAllTag
   char **prefList;
   rv = m_tagPrefBranch->GetChildList("", &prefCount, &prefList);
   NS_ENSURE_SUCCESS(rv, rv);
   // sort them by key for ease of processing
   NS_QuickSort(prefList, prefCount, sizeof(char*), CompareMsgTagKeys, nullptr);
 
   // build an array of nsIMsgTag elements from the orderered list
   // it's at max the same size as the preflist, but usually only about half
-  nsIMsgTag** tagArray = (nsIMsgTag**) NS_Alloc(sizeof(nsIMsgTag*) * prefCount);
+  nsIMsgTag** tagArray = (nsIMsgTag**) moz_xmalloc(sizeof(nsIMsgTag*) * prefCount);
 
   if (!tagArray)
   {
     NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, prefList);
     return NS_ERROR_OUT_OF_MEMORY;
   }
   uint32_t currentTagIndex = 0;
   nsMsgTag *newMsgTag;
--- a/mailnews/base/src/nsSubscribableServer.cpp
+++ b/mailnews/base/src/nsSubscribableServer.cpp
@@ -418,17 +418,17 @@ nsSubscribableServer::FreeSubtree(Subscr
             rv = FreeSubtree(node->nextSibling);
             NS_ENSURE_SUCCESS(rv,rv);
             node->nextSibling = nullptr;
         }
 
 #ifdef HAVE_SUBSCRIBE_DESCRIPTION
         NS_ASSERTION(node->description == nullptr, "you need to free the description");
 #endif
-        NS_Free(node->name);
+        free(node->name);
 #if 0
         node->name = nullptr;
         node->parent = nullptr;
         node->lastChild = nullptr;
         node->cachedChild = nullptr;
 #endif
 
         PR_Free(node);
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -561,17 +561,17 @@ NS_IMETHODIMP nsMsgDBFolder::ClearNewMes
   {
     uint32_t numNewKeys;
     nsMsgKey *newMessageKeys;
     rv = mDatabase->GetNewList(&numNewKeys, &newMessageKeys);
     if (NS_SUCCEEDED(rv) && newMessageKeys)
     {
       m_saveNewMsgs.Clear();
       m_saveNewMsgs.AppendElements(newMessageKeys, numNewKeys);
-      NS_Free(newMessageKeys);
+      free(newMessageKeys);
     }
     mDatabase->ClearNewList(true);
   }
   if (!dbWasCached)
     SetMsgDatabase(nullptr);
 
   m_newMsgs.Clear();
   mNumNewBiffMessages = 0;
@@ -956,17 +956,17 @@ nsMsgDBFolder::SetMsgDatabase(nsIMsgData
       uint32_t numNewKeys;
       nsMsgKey *newMessageKeys;
       nsresult rv = mDatabase->GetNewList(&numNewKeys, &newMessageKeys);
       if (NS_SUCCEEDED(rv) && newMessageKeys)
       {
         m_newMsgs.Clear();
         m_newMsgs.AppendElements(newMessageKeys, numNewKeys);
       }
-      NS_Free(newMessageKeys);
+      free(newMessageKeys);
     }
   }
   mDatabase = aMsgDatabase;
 
   if (aMsgDatabase)
     aMsgDatabase->AddListener(this);
   return NS_OK;
 }
@@ -2292,18 +2292,18 @@ nsMsgDBFolder::SpamFilterClassifyMessage
 
   uint32_t count;
   uint32_t *proIndices;
   uint32_t *antiIndices;
   rv = traitService->GetEnabledIndices(&count, &proIndices, &antiIndices);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = aJunkMailPlugin->ClassifyTraitsInMessage(aURI, count, proIndices, antiIndices, this, aMsgWindow, this);
-  NS_Free(proIndices);
-  NS_Free(antiIndices);
+  free(proIndices);
+  free(antiIndices);
   return rv;
 }
 
 nsresult
 nsMsgDBFolder::SpamFilterClassifyMessages(const char **aURIArray, uint32_t aURICount, nsIMsgWindow *aMsgWindow, nsIJunkMailPlugin *aJunkMailPlugin)
 {
 
   nsresult rv;
@@ -2313,18 +2313,18 @@ nsMsgDBFolder::SpamFilterClassifyMessage
   uint32_t count;
   uint32_t *proIndices;
   uint32_t *antiIndices;
   rv = traitService->GetEnabledIndices(&count, &proIndices, &antiIndices);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = aJunkMailPlugin->ClassifyTraitsInMessages(aURICount, aURIArray, count,
       proIndices, antiIndices, this, aMsgWindow, this);
-  NS_Free(proIndices);
-  NS_Free(antiIndices);
+  free(proIndices);
+  free(antiIndices);
   return rv;
 }
 
 NS_IMETHODIMP
 nsMsgDBFolder::OnMessageClassified(const char *aMsgURI,
                                    nsMsgJunkStatus aClassification,
                                    uint32_t aJunkPercent)
 {
@@ -2614,18 +2614,18 @@ nsMsgDBFolder::CallFilterPlugins(nsIMsgW
         GetInheritedStringProperty(property.get(), isEnabledOnFolder);
         if (isEnabledOnFolder.EqualsLiteral("false"))
           filterForOther = false;
         // We might have to allow a "true" override in the future, but
         // for now there is no way for that to affect the processing
         break;
       }
     }
-    NS_Free(proIndices);
-    NS_Free(antiIndices);
+    free(proIndices);
+    free(antiIndices);
   }
 
   // Do we need to apply message filters?
   bool filterPostPlugin = false; // Do we have a post-analysis filter?
   nsCOMPtr<nsIMsgFilterList> filterList;
   GetFilterList(aMsgWindow, getter_AddRefs(filterList));
   if (filterList)
   {
@@ -2668,17 +2668,17 @@ nsMsgDBFolder::CallFilterPlugins(nsIMsgW
   nsTArray<nsMsgKey> newMessageKeys;
   // Start from m_saveNewMsgs (and clear its current state).  m_saveNewMsgs is
   // where we stash the list of new messages when we are told to clear the list
   // of new messages by the UI (which purges the list from the nsMsgDatabase).
   newMessageKeys.SwapElements(m_saveNewMsgs);
   if (numNewKeys)
     newMessageKeys.AppendElements(newKeys, numNewKeys);
 
-  NS_Free(newKeys);
+  free(newKeys);
 
   // build up list of keys to classify
   nsTArray<nsMsgKey> classifyMsgKeys;
   nsCString uri;
 
   uint32_t numNewMessages = newMessageKeys.Length();
   for (uint32_t i = 0 ; i < numNewMessages ; ++i)
   {
--- a/mailnews/compose/src/nsMsgCompFields.cpp
+++ b/mailnews/compose/src/nsMsgCompFields.cpp
@@ -603,17 +603,17 @@ nsMsgCompFields::SplitRecipients(const n
   nsCOMArray<msgIAddressObject> header(EncodedHeader(NS_ConvertUTF16toUTF8(aRecipients)));
   nsTArray<nsString> results;
   if (aEmailAddressOnly)
     ExtractEmails(header, results);
   else
     ExtractDisplayAddresses(header, results);
 
   uint32_t count = results.Length();
-  char16_t **result = (char16_t **)NS_Alloc(sizeof(char16_t *) * count);
+  char16_t **result = (char16_t **)moz_xmalloc(sizeof(char16_t *) * count);
   for (uint32_t i = 0; i < count; ++i)
     result[i] = ToNewUnicode(results[i]);
 
   *aResult = result;
   *aLength = count;
   return NS_OK;
 }
 
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -1631,17 +1631,17 @@ nsMsgComposeAndSend::GetBodyFromEditor()
       {
         mOriginalHTMLBody = ToNewCString(newBody);
       }
     }
     else {
       mOriginalHTMLBody = ToNewCString(attachment1_body);
     }
 
-    NS_Free(bodyText);    //Don't need it anymore
+    free(bodyText);    //Don't need it anymore
   }
   else
     return NS_ERROR_FAILURE;
 
   rv = SnarfAndCopyBody(attachment1_body, TEXT_HTML);
 
   return rv;
 }
@@ -3367,17 +3367,17 @@ nsMsgComposeAndSend::DeliverFileAsMail()
     buf = convbuf;
   }
 
   nsCString escaped_buf;
   MsgEscapeString(nsDependentCString(buf), nsINetUtil::ESCAPE_URL_PATH, escaped_buf);
 
   if (!escaped_buf.IsEmpty())
   {
-    NS_Free(buf);
+    free(buf);
     buf = ToNewCString(escaped_buf);
   }
 
   nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
   if (NS_SUCCEEDED(rv) && smtpService)
   {
     MsgDeliveryListener *deliveryListener = new MsgDeliveryListener(this, false);
     if (!deliveryListener)
--- a/mailnews/compose/src/nsSmtpProtocol.cpp
+++ b/mailnews/compose/src/nsSmtpProtocol.cpp
@@ -1510,17 +1510,17 @@ nsresult nsSmtpProtocol::AuthLoginStep1(
   }
   else
     return (NS_ERROR_COMMUNICATIONS_ERROR);
 
   status = SendData(buffer, true);
   m_nextState = SMTP_RESPONSE;
   m_nextStateAfterResponse = SMTP_AUTH_LOGIN_RESPONSE;
   SetFlag(SMTP_PAUSE_FOR_READ);
-  NS_Free(base64Str);
+  free(base64Str);
 
   return (status);
 }
 
 nsresult nsSmtpProtocol::AuthLoginStep2()
 {
   /* use cached smtp password first
   * if not then use cached pop password
@@ -1572,17 +1572,17 @@ nsresult nsSmtpProtocol::AuthLoginStep2(
         if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
 
         nsCString userName;
         rv = smtpServer->GetUsername(userName);
 
         PR_snprintf(buffer, sizeof(buffer), "%s %s", userName.get(), encodedDigest.get());
         char *base64Str = PL_Base64Encode(buffer, strlen(buffer), nullptr);
         PR_snprintf(buffer, sizeof(buffer), "%s" CRLF, base64Str);
-        NS_Free(base64Str);
+        free(base64Str);
       }
       if (NS_FAILED(rv))
         PR_snprintf(buffer, sizeof(buffer), "*" CRLF);
     }
     else if (m_currentAuthMethod == SMTP_AUTH_NTLM_ENABLED ||
              m_currentAuthMethod == SMTP_AUTH_MSN_ENABLED)
     {
       MOZ_LOG(SMTPLogModule, mozilla::LogLevel::Debug, ("NTLM/MSN auth, step 2"));
@@ -1591,17 +1591,17 @@ nsresult nsSmtpProtocol::AuthLoginStep2(
       PR_snprintf(buffer, sizeof(buffer), "%.509s" CRLF, response.get());
     }
     else if (m_currentAuthMethod == SMTP_AUTH_PLAIN_ENABLED ||
              m_currentAuthMethod == SMTP_AUTH_LOGIN_ENABLED)
     {
       MOZ_LOG(SMTPLogModule, mozilla::LogLevel::Debug, ("PLAIN/LOGIN auth, step 2"));
       char *base64Str = PL_Base64Encode(password.get(), password.Length(), nullptr);
       PR_snprintf(buffer, sizeof(buffer), "%.256s" CRLF, base64Str);
-      NS_Free(base64Str);
+      free(base64Str);
     }
     else
       return NS_ERROR_COMMUNICATIONS_ERROR;
 
     status = SendData(buffer, true);
     m_nextState = SMTP_RESPONSE;
     m_nextStateAfterResponse = SMTP_AUTH_LOGIN_RESPONSE;
     SetFlag(SMTP_PAUSE_FOR_READ);
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -3605,28 +3605,28 @@ nsresult nsMsgDatabase::CharPtrToRowCell
   yarn.mYarn_Buf = (void *) charPtr;
   yarn.mYarn_Size = PL_strlen((const char *) yarn.mYarn_Buf) + 1;
   yarn.mYarn_Fill = yarn.mYarn_Size - 1;
   yarn.mYarn_Form = 0;  // what to do with this? we're storing csid in the msg hdr...
 
   return row->AddColumn(GetEnv(),  columnToken, &yarn);
 }
 
-// caller must NS_Free result
+// caller must free result
 nsresult nsMsgDatabase::RowCellColumnToCharPtr(nsIMdbRow *row, mdb_token columnToken, char **result)
 {
   nsresult  err = NS_ERROR_NULL_POINTER;
 
   if (row && result)
   {
     struct mdbYarn yarn;
     err = row->AliasCellYarn(GetEnv(), columnToken, &yarn);
     if (NS_SUCCEEDED(err))
     {
-      *result = (char *)NS_Alloc(yarn.mYarn_Fill + 1);
+      *result = (char *)moz_xmalloc(yarn.mYarn_Fill + 1);
       if (*result)
       {
         if (yarn.mYarn_Fill > 0)
           memcpy(*result, yarn.mYarn_Buf, yarn.mYarn_Fill);
         (*result)[yarn.mYarn_Fill] = '\0';
       }
       else
         err = NS_ERROR_OUT_OF_MEMORY;
--- a/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
+++ b/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
@@ -1692,17 +1692,17 @@ void nsBayesianFilter::classifyMessage(
           tokenStrings.AppendElement(ToNewUnicode(NS_ConvertUTF8toUTF16(
               tokens[ta.mTokenIndex].mWord)));
         }
 
         aDetailListener->OnMessageTraitDetails(messageURI, aProTraits[traitIndex],
             usedTokenCount, (const char16_t**)tokenStrings.Elements(),
             tokenPercents.Elements(), runningPercents.Elements());
         for (uint32_t tokenIndex = 0; tokenIndex < usedTokenCount; tokenIndex++)
-          NS_Free(tokenStrings[tokenIndex]);
+          free(tokenStrings[tokenIndex]);
       }
 
       uint32_t proPercent = static_cast<uint32_t>(prob*100. + .5);
 
       // directly classify junk to maintain backwards compatibility
       if (aProTraits[traitIndex] == kJunkTrait)
       {
         bool isJunk = (prob >= mJunkProbabilityThreshold);
@@ -1735,19 +1735,19 @@ void nsBayesianFilter::classifyMessage(
       if (aTraitListener)
       {
         traits.AppendElement(aProTraits[traitIndex]);
         percents.AppendElement(proPercent);
       }
 
       // free aliases arrays returned from XPCOM
       if (proAliasesLengths[traitIndex])
-        NS_Free(proAliasArrays[traitIndex]);
+        free(proAliasArrays[traitIndex]);
       if (antiAliasesLengths[traitIndex])
-        NS_Free(antiAliasArrays[traitIndex]);
+        free(antiAliasArrays[traitIndex]);
     }
 
     if (aTraitListener)
       aTraitListener->OnMessageTraitsClassified(messageURI,
           traits.Length(), traits.Elements(), percents.Elements());
 
     delete[] tokens;
     // reuse mAnalysisStore without clearing memory
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -8400,17 +8400,17 @@ nsImapMailFolder::CopyFileToOfflineStore
     {
       newLine = inputStreamBuffer->ReadNextLine(inputStream, numBytesInLine, needMoreData);
       if (newLine)
       {
         msgParser->ParseAFolderLine(newLine, numBytesInLine);
         if (offlineStore)
           rv = offlineStore->Write(newLine, numBytesInLine, &bytesWritten);
 
-        NS_Free(newLine);
+        free(newLine);
         NS_ENSURE_SUCCESS(rv, rv);
       }
     } while (newLine);
 
     msgParser->FinishHeader();
     uint32_t resultFlags;
     if (offlineStore)
       fakeHdr->OrFlags(nsMsgMessageFlags::Offline | nsMsgMessageFlags::Read, &resultFlags);
--- a/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mailnews/imap/src/nsImapProtocol.cpp
@@ -2516,17 +2516,17 @@ void nsImapProtocol::ProcessSelectedStat
         bool more;
         m_imapMailFolderSink->GetMsgHdrsToDownload(&more,
                                                    &m_progressExpectedNumber,
                                                    &msgCount,
                                                    &msgIdList);
         if (msgIdList)
         {
           FolderHeaderDump(msgIdList, msgCount);
-          NS_Free(msgIdList);
+          free(msgIdList);
           m_runningUrl->SetMoreHeadersToDownload(more);
           // We're going to be re-running this url.
           if (more)
             m_runningUrl->SetRerunningUrl(true);
         }
         HeaderFetchCompleted();
       }
       else
@@ -3533,17 +3533,17 @@ nsImapProtocol::FetchMessage(const nsCSt
           headersToDL = strdup(dbHeaders);
         else
           headersToDL = PR_smprintf("%s %s",dbHeaders, arbitraryHeaders.get());
 
         if (gUseEnvelopeCmd)
           what = PR_smprintf(" ENVELOPE BODY.PEEK[HEADER.FIELDS (%s)])", headersToDL);
         else
           what = PR_smprintf(" BODY.PEEK[HEADER.FIELDS (%s)])",headersToDL);
-        NS_Free(headersToDL);
+        free(headersToDL);
         if (what)
         {
           commandString.AppendLiteral(" %s (UID ");
            if (m_isGmailServer)
             commandString.AppendLiteral("X-GM-MSGID X-GM-THRID X-GM-LABELS ");
           if (aolImapServer)
             commandString.AppendLiteral(" XAOL.SIZE") ;
           else
@@ -4254,17 +4254,17 @@ void nsImapProtocol::ProcessMailboxUpdat
   if (GetServerStateParser().LastCommandSuccessful())
   {
     if (entered_waitForBodyIdsMonitor)
       m_waitForBodyIdsMonitor.Exit();
 
     if (msgIdList && !DeathSignalReceived() && GetServerStateParser().LastCommandSuccessful())
     {
       FolderHeaderDump(msgIdList, msgCount);
-      NS_Free( msgIdList);
+      free( msgIdList);
     }
     HeaderFetchCompleted();
       // this might be bogus, how are we going to do pane notification and stuff when we fetch bodies without
       // headers!
   }
   else if (entered_waitForBodyIdsMonitor) // need to exit this monitor if death signal received
     m_waitForBodyIdsMonitor.Exit();
 
@@ -6527,17 +6527,17 @@ void nsImapProtocol::OnRefreshAllACLs()
     mb = m_listedMailboxList.ElementAt(i);
     if (mb) // paranoia
     {
       char *onlineName = nullptr;
       m_runningUrl->AllocateServerPath(PromiseFlatCString(mb->GetMailboxName()).get(), mb->GetDelimiter(), &onlineName);
       if (onlineName)
       {
         RefreshACLForFolder(onlineName);
-        NS_Free(onlineName);
+        free(onlineName);
       }
       PercentProgressUpdateEvent(NULL, count, total);
       delete mb;
       count++;
     }
   }
   m_listedMailboxList.Clear();
 
--- a/mailnews/imap/src/nsImapServerResponseParser.cpp
+++ b/mailnews/imap/src/nsImapServerResponseParser.cpp
@@ -1599,17 +1599,17 @@ void nsImapServerResponseParser::parse_a
         AdvanceToNextToken();
         char *hostName = CreateNilString();
         AdvanceToNextToken();
         addressLine += mailboxName;
         if (hostName)
         {
           addressLine += '@';
           addressLine += hostName;
-          NS_Free(hostName);
+          free(hostName);
         }
         if (personalName)
         {
           addressLine += " (";
           addressLine += personalName;
           addressLine += ')';
         }
       }
@@ -1636,17 +1636,17 @@ void nsImapServerResponseParser::interna
   AdvanceToNextToken();
   if (ContinueParse())
   {
     nsAutoCString dateLine("Date: ");
     char *strValue = CreateNilString();
     if (strValue)
     {
       dateLine += strValue;
-      NS_Free(strValue);
+      free(strValue);
     }
     fServerConnection.HandleMessageDownLoadLine(dateLine.get(), false);
   }
   // advance the parser.
   AdvanceToNextToken();
 }
 
 void nsImapServerResponseParser::flags()
--- a/mailnews/imap/src/nsImapService.cpp
+++ b/mailnews/imap/src/nsImapService.cpp
@@ -2079,17 +2079,17 @@ nsresult nsImapService::OfflineAppendFro
           uint32_t numBytesInLine = 0;
           do
           {
             newLine = inputStreamBuffer->ReadNextLine(inputStream, numBytesInLine, needMoreData); 
             if (newLine)
             {
               msgParser->ParseAFolderLine(newLine, numBytesInLine);
               rv = offlineStore->Write(newLine, numBytesInLine, &bytesWritten);
-              NS_Free(newLine);
+              free(newLine);
             }
           } while (newLine);
           msgParser->FinishHeader();
 
           nsCOMPtr<nsIMsgDBHdr> fakeHdr;
           msgParser->GetNewMsgHdr(getter_AddRefs(fakeHdr));
           if (fakeHdr)
           {
--- a/mailnews/imap/src/nsImapUrl.cpp
+++ b/mailnews/imap/src/nsImapUrl.cpp
@@ -798,17 +798,17 @@ NS_IMETHODIMP nsImapUrl::AddOnlineDirect
           PL_strcat(newOnlineName, onlineMailboxName);
         }
       }
     }
   }
   if (directory)
     *directory = newOnlineName;
   else if (newOnlineName)
-    NS_Free(newOnlineName);
+    free(newOnlineName);
   return rv;
 }
 
 // Converts from canonical format (hierarchy is indicated by '/' and all real slashes ('/') are escaped)
 // to the real online name on the server.
 NS_IMETHODIMP nsImapUrl::AllocateServerPath(const char * canonicalPath, char onlineDelimiter, char ** aAllocatedPath)
 {
   nsresult retVal = NS_OK;
@@ -823,24 +823,24 @@ NS_IMETHODIMP nsImapUrl::AllocateServerP
     rv = strdup("");
 
   if (delimiterToUse != '/')
     UnescapeSlashes(rv);
   char *onlineNameAdded = nullptr;
   AddOnlineDirectoryIfNecessary(rv, &onlineNameAdded);
   if (onlineNameAdded)
   {
-    NS_Free(rv);
+    free(rv);
     rv = onlineNameAdded;
   }
 
   if (aAllocatedPath)
     *aAllocatedPath = rv;
   else
-    NS_Free(rv);
+    free(rv);
 
   return retVal;
 }
 
 // escape '/' as ^, ^ -> ^^ - use UnescapeSlashes to revert
 /* static */ nsresult nsImapUrl::EscapeSlashes(const char *sourcePath, char **resultPath)
 {
   NS_ENSURE_ARG(sourcePath);
--- a/mailnews/import/outlook/src/MapiApi.cpp
+++ b/mailnews/import/outlook/src/MapiApi.cpp
@@ -1355,17 +1355,17 @@ void CMapiApi::ReportUIDProp(const char 
       MAPI_TRACE1("%s - INVALID, expecting 16 bytes of binary data for UID\n", pTag);
     }
     else {
       nsIID  uid;
       memcpy(&uid, pVal->Value.bin.lpb, 16);
       char *  pStr = uid.ToString();
       if (pStr) {
         MAPI_TRACE2("%s %s\n", pTag, (const char *)pStr);
-        NS_Free(pStr);
+        free(pStr);
       }
     }
   }
   else if (pVal && (PROP_TYPE(pVal->ulPropTag) == PT_NULL)) {
     MAPI_TRACE1("%s {NULL}\n", pTag);
   }
   else if (pVal && (PROP_TYPE(pVal->ulPropTag) == PT_ERROR)) {
     MAPI_TRACE1("%s {Error retrieving property}\n", pTag);
@@ -1641,23 +1641,23 @@ void CMapiFolderList::DumpList(void)
     depth *= 2;
     if (depth > 255)
       depth = 255;
     memset(prefix, ' ', depth);
     prefix[depth] = 0;
 #ifdef MAPI_DEBUG
         char *ansiStr = ToNewCString(str);
     MAPI_TRACE2("%s%s: ", prefix, ansiStr);
-    NS_Free(ansiStr);
+    free(ansiStr);
 #endif
     pFolder->GetFilePath(str);
 #ifdef MAPI_DEBUG
         ansiStr = ToNewCString(str);
     MAPI_TRACE2("depth=%d, filePath=%s\n", pFolder->GetDepth(), ansiStr);
-    NS_Free(ansiStr);
+    free(ansiStr);
 #endif
   }
   MAPI_TRACE0("---------------------------------------------\n");
 }
 
 
 CMapiFolder::CMapiFolder()
 {
--- a/mailnews/import/outlook/src/MapiMessage.cpp
+++ b/mailnews/import/outlook/src/MapiMessage.cpp
@@ -1115,23 +1115,23 @@ bool CMapiMessage::AddAttachment(DWORD a
 }
 
 void CMapiMessage::ClearAttachment(attach_data* data)
 {
   if (data->delete_file && data->tmp_file)
     data->tmp_file->Remove(false);
 
   if (data->type)
-    NS_Free(data->type);
+    free(data->type);
   if (data->encoding)
-    NS_Free(data->encoding);
+    free(data->encoding);
   if (data->real_name)
-    NS_Free(data->real_name);
+    free(data->real_name);
   if (data->cid)
-    NS_Free(data->cid);
+    free(data->cid);
 
   delete data;
 }
 
 void CMapiMessage::ClearAttachments()
 {
   std::for_each(m_stdattachments.begin(), m_stdattachments.end(), ClearAttachment);
   m_stdattachments.clear();
--- a/mailnews/import/outlook/src/nsOutlookImport.cpp
+++ b/mailnews/import/outlook/src/nsOutlookImport.cpp
@@ -381,17 +381,17 @@ ImportOutlookMailImpl::ImportMailbox(nsI
 
   nsString  success;
   nsString  error;
   bool abort = false;
   nsString name;
   char16_t *pName;
   if (NS_SUCCEEDED( pSource->GetDisplayName( &pName))) {
     name = pName;
-    NS_Free( pName);
+    free( pName);
  }
 
   uint32_t mailSize = 0;
   pSource->GetSize(&mailSize);
   if (mailSize == 0) {
     ReportSuccess(name, 0, &success);
     SetLogs(success, error, pErrorLog, pSuccessLog);
     return NS_OK;
--- a/mailnews/import/src/nsImportAddressBooks.cpp
+++ b/mailnews/import/src/nsImportAddressBooks.cpp
@@ -138,17 +138,17 @@ nsImportGenericAddressBooks::nsImportGen
 
   nsImportStringBundle::GetStringBundle(IMPORT_MSGS_URL, getter_AddRefs(m_stringBundle));
 }
 
 
 nsImportGenericAddressBooks::~nsImportGenericAddressBooks()
 {
   if (m_description)
-    NS_Free(m_description);
+    free(m_description);
 }
 
 
 
 NS_IMPL_ISUPPORTS(nsImportGenericAddressBooks, nsIImportGeneric)
 
 
 NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISupports **_retval)
@@ -219,17 +219,17 @@ NS_IMETHODIMP nsImportGenericAddressBook
       bool      found = false;
       rv = m_pInterface->GetSampleData(rNum, &found, &pData);
       if (NS_FAILED(rv))
         return rv;
       if (found) {
         data->SetData(nsDependentString(pData));
         data.forget(_retval);
       }
-      NS_Free(pData);
+      free(pData);
     }
   }
 
   return NS_OK;
 }
 
 
 NS_IMETHODIMP nsImportGenericAddressBooks::SetData(const char *dataId, nsISupports *item)
@@ -324,17 +324,17 @@ void nsImportGenericAddressBooks::GetDef
 {
   if (!m_pInterface)
     return;
 
   if ((m_pLocation && m_gotLocation) || m_autoFind)
     return;
 
   if (m_description)
-    NS_Free(m_description);
+    free(m_description);
   m_description = nullptr;
   m_pInterface->GetAutoFind(&m_description, &m_autoFind);
   m_gotLocation = true;
   if (m_autoFind) {
     m_found = true;
     m_userVerify = false;
     return;
   }
@@ -722,17 +722,17 @@ void nsImportGenericAddressBooks::Report
 {
   if (!pStream)
     return;
   // load the error string
   char16_t *pFmt = nsImportStringBundle::GetStringByID(IMPORT_ERROR_GETABOOK, aBundle);
   nsString pText;
   nsTextFormatter::ssprintf(pText, pFmt, pName);
   pStream->Append(pText);
-  NS_Free(pFmt);
+  free(pFmt);
   pStream->AppendLiteral(MSG_LINEBREAK);
 }
 
 static void ImportAddressThread(void *stuff)
 {
   IMPORT_LOG0("In Begin ImportAddressThread\n");
 
   AddressThreadData *pData = (AddressThreadData *)stuff;
@@ -788,21 +788,21 @@ static void ImportAddressThread(void *st
                                                        db,
                                                        pData->fieldMap,
                                                        pData->ldifService,
                                                        &pError,
                                                        &pSuccess,
                                                        &fatalError);
           if (NS_SUCCEEDED(rv) && pSuccess) {
             success.Append(pSuccess);
-            NS_Free(pSuccess);
+            free(pSuccess);
           }
           if (pError) {
             error.Append(pError);
-            NS_Free(pError);
+            free(pError);
           }
         }
         else {
           nsImportGenericAddressBooks::ReportError(name.get(), &error, pData->stringBundle);
         }
 
         pData->currentSize = 0;
         pData->currentTotal += size;
--- a/mailnews/import/src/nsImportFieldMap.cpp
+++ b/mailnews/import/src/nsImportFieldMap.cpp
@@ -329,17 +329,17 @@ NS_IMETHODIMP nsImportFieldMap::SetField
   default:
     /* Get the field description, and add it as an anonymous attr? */
     /* OR WHAT???? */
     {
       rv = NS_ERROR_FAILURE;
     }
   }
 
-  NS_Free(pVal);
+  free(pVal);
 
   return rv;
 }
 
 
 nsresult nsImportFieldMap::Allocate(int32_t newSize)
 {
   if (newSize <= m_allocated)
--- a/mailnews/import/src/nsImportMail.cpp
+++ b/mailnews/import/src/nsImportMail.cpp
@@ -564,17 +564,17 @@ void nsImportGenericMail::ReportError(in
   if (!pStream)
     return;
 
   // load the error string
   char16_t *pFmt = nsImportStringBundle::GetStringByID(id, aBundle);
   nsString pText;
   nsTextFormatter::ssprintf(pText, pFmt, pName);
   pStream->Append(pText);
-  NS_Free(pFmt);
+  free(pFmt);
   pStream->Append(NS_ConvertASCIItoUTF16(MSG_LINEBREAK));
 }
 
 
 void nsImportGenericMail::SetLogs(nsString& success, nsString& error, nsISupportsString *pSuccess, nsISupportsString *pError)
 {
     nsAutoString str;
     if (pSuccess) {
@@ -739,17 +739,17 @@ ImportMailThread(void *stuff)
           break;
         }
       }
       depth = newDepth;
       pName = nullptr;
       box->GetDisplayName(&pName);
       if (pName) {
         lastName = pName;
-        NS_Free(pName);
+        free(pName);
       }
       else
         lastName.AssignLiteral("Unknown!");
 
       // translate the folder name if we are doing migration, but
       // only for special folders which are at the root level
       if (pData->performingMigration && depth == 1)
         pData->mailImport->TranslateFolderName(lastName, lastName);
@@ -781,21 +781,21 @@ ImportMailThread(void *stuff)
       if (size && import && newFolder && NS_SUCCEEDED(rv)) {
         bool fatalError = false;
         pData->currentSize = size;
         char16_t *pSuccess = nullptr;
         char16_t *pError = nullptr;
         rv = pData->mailImport->ImportMailbox(box, newFolder, &pError, &pSuccess, &fatalError);
         if (pError) {
           error.Append(pError);
-          NS_Free(pError);
+          free(pError);
         }
         if (pSuccess) {
           success.Append(pSuccess);
-          NS_Free(pSuccess);
+          free(pSuccess);
         }
 
         pData->currentSize = 0;
         pData->currentTotal += size;
         
         // commit to the db synchronously, but using a proxy since it doesn't like being used
         // elsewhere than from the main thread.
         // OK, we've copied the actual folder/file over if the folder size is not 0
--- a/mailnews/import/text/src/nsTextImport.cpp
+++ b/mailnews/import/text/src/nsTextImport.cpp
@@ -326,32 +326,32 @@ void ImportAddressImpl::ReportSuccess(ns
 
   // load the success string
   char16_t *pFmt =
     nsImportStringBundle::GetStringByID(TEXTIMPORT_ADDRESS_SUCCESS, pBundle);
 
   nsString pText;
   nsTextFormatter::ssprintf(pText, pFmt, name.get());
   pStream->Append(pText);
-  NS_Free(pFmt);
+  free(pFmt);
   pStream->Append(char16_t('\n'));
 }
 
 void ImportAddressImpl::ReportError(int32_t errorNum, nsString& name,
                                     nsString *pStream, nsIStringBundle* pBundle)
 {
   if (!pStream)
     return;
 
   // load the error string
   char16_t *pFmt = nsImportStringBundle::GetStringByID(errorNum, pBundle);
   nsString pText;
   nsTextFormatter::ssprintf(pText, pFmt, name.get());
   pStream->Append(pText);
-  NS_Free(pFmt);
+  free(pFmt);
   pStream->Append(char16_t('\n'));
 }
 
 void ImportAddressImpl::SetLogs(nsString& success, nsString& error, char16_t **pError, char16_t **pSuccess)
 {
   if (pError)
     *pError = ToNewUnicode(error);
   if (pSuccess)
--- a/mailnews/import/vcard/src/nsVCardImport.cpp
+++ b/mailnews/import/vcard/src/nsVCardImport.cpp
@@ -286,33 +286,33 @@ void ImportVCardAddressImpl::ReportSucce
 
   // load the success string
   char16_t *pFmt = nsImportStringBundle::GetStringByName(
       "vCardImportAddressSuccess", pBundle);
 
   nsString pText;
   nsTextFormatter::ssprintf(pText, pFmt, name.get());
   pStream->Append(pText);
-  NS_Free(pFmt);
+  free(pFmt);
   pStream->Append(char16_t('\n'));
 }
 
 void ImportVCardAddressImpl::ReportError(
     const char *errorName, nsString& name, nsString *pStream,
     nsIStringBundle* pBundle)
 {
   if (!pStream)
     return;
 
   // load the error string
   char16_t *pFmt = nsImportStringBundle::GetStringByName(errorName, pBundle);
   nsString pText;
   nsTextFormatter::ssprintf(pText, pFmt, name.get());
   pStream->Append(pText);
-  NS_Free(pFmt);
+  free(pFmt);
   pStream->Append(char16_t('\n'));
 }
 
 void ImportVCardAddressImpl::SetLogs(
     nsString& success, nsString& error,
     char16_t **pError, char16_t **pSuccess)
 { 
   if (pError) 
--- a/mailnews/local/src/nsMsgMaildirStore.cpp
+++ b/mailnews/local/src/nsMsgMaildirStore.cpp
@@ -1209,17 +1209,17 @@ nsresult MaildirStoreParser::ParseNextMe
     // from the file size. So we can do this in one time slice.
     do
     {
       newLine = inputStreamBuffer->ReadNextLine(inputStream, numBytesInLine,
                                                 needMoreData);
       if (newLine)
       {
         msgParser->ParseAFolderLine(newLine, numBytesInLine);
-        NS_Free(newLine);
+        free(newLine);
       }
     } while (newLine && numBytesInLine > 0);
 
     msgParser->FinishHeader();
     // A single message needs to be less than 4GB
     newMsgHdr->SetMessageSize((uint32_t) fileSize);
     m_db->AddNewHdrToDB(newMsgHdr, true);
     nsAutoCString storeToken;
--- a/mailnews/mime/cthandlers/glue/nsMimeContentTypeHandler.cpp
+++ b/mailnews/mime/cthandlers/glue/nsMimeContentTypeHandler.cpp
@@ -24,17 +24,17 @@ nsMimeContentTypeHandler::nsMimeContentT
   NS_ASSERTION(callback, "nsMimeContentTypeHandler should be initialized with non-null callback");
   mimeType = PL_strdup(aMimeType);
   realCreateContentTypeHandlerClass = callback;
 }
 
 nsMimeContentTypeHandler::~nsMimeContentTypeHandler(void)
 {
   if (mimeType) {
-    NS_Free(mimeType);
+    free(mimeType);
     mimeType = 0;
   }
   realCreateContentTypeHandlerClass = 0;
 }
 
 // Get the content type if necessary
 nsresult
 nsMimeContentTypeHandler::GetContentType(char **contentType)
--- a/mailnews/mime/emitters/nsMimeBaseEmitter.cpp
+++ b/mailnews/mime/emitters/nsMimeBaseEmitter.cpp
@@ -100,17 +100,17 @@ nsMimeBaseEmitter::~nsMimeBaseEmitter(vo
     for (size_t i = 0; i < mAttachArray->Length(); i++)
     {
       attachmentInfoType *attachInfo = mAttachArray->ElementAt(i);
       if (!attachInfo)
         continue;
 
       PR_FREEIF(attachInfo->contentType);
       if (attachInfo->displayName)
-        NS_Free(attachInfo->displayName);
+        free(attachInfo->displayName);
       PR_FREEIF(attachInfo->urlSpec);
       PR_FREEIF(attachInfo);
     }
     delete mAttachArray;
   }
 
   // Cleanup allocated header arrays...
   CleanupHeaderArray(mHeaderArray);
--- a/mailnews/mime/emitters/nsMimeXmlEmitter.cpp
+++ b/mailnews/mime/emitters/nsMimeXmlEmitter.cpp
@@ -105,17 +105,17 @@ nsMimeXmlEmitter::WriteXMLTag(const char
   UtilityWrite(": ");
   UtilityWrite("</headerdisplayname>");
 
   // Now write out the actual value itself and move on!
   //
   UtilityWrite(newValue.get());
   UtilityWrite("</header>");
 
-  NS_Free(upCaseTag);
+  free(upCaseTag);
 
   return NS_OK;
 }
 
 // Header handling routines.
 nsresult
 nsMimeXmlEmitter::StartHeader(bool rootMailHeader, bool headerOnly, const char *msgID,
                            const char *outCharset)
--- a/mailnews/mime/src/mimemoz2.cpp
+++ b/mailnews/mime/src/mimemoz2.cpp
@@ -953,20 +953,20 @@ mime_display_stream_complete (nsMIMESess
       msd->options = 0;
     }
   }
 
   if (msd->headers)
     MimeHeaders_free (msd->headers);
 
   if (msd->url_name)
-    NS_Free(msd->url_name);
+    free(msd->url_name);
 
   if (msd->orig_url_name)
-      NS_Free(msd->orig_url_name);
+      free(msd->orig_url_name);
 
   delete msd;
 }
 
 extern "C" void
 mime_display_stream_abort (nsMIMESession *stream, int status)
 {
   mime_stream_data *msd = (mime_stream_data *) ((nsMIMESession *)stream)->data_object;
@@ -988,20 +988,20 @@ mime_display_stream_abort (nsMIMESession
       msd->options = 0;
     }
   }
 
   if (msd->headers)
     MimeHeaders_free (msd->headers);
 
   if (msd->url_name)
-    NS_Free(msd->url_name);
+    free(msd->url_name);
 
   if (msd->orig_url_name)
-      NS_Free(msd->orig_url_name);
+      free(msd->orig_url_name);
 
   delete msd;
 }
 
 static int
 mime_output_init_fn (const char *type,
                      const char *charset,
                      const char *name,
--- a/mailnews/mime/src/nsStreamConverter.cpp
+++ b/mailnews/mime/src/nsStreamConverter.cpp
@@ -198,17 +198,17 @@ bridge_new_new_uri(void *bridgeStream, n
             }
           }
         }
         nsAutoCString urlString;
         if (NS_SUCCEEDED(aURI->GetSpec(urlString)))
         {
           if (!urlString.IsEmpty())
           {
-            NS_Free(*url_name);
+            free(*url_name);
             *url_name = ToNewCString(urlString);
             if (!(*url_name))
               return NS_ERROR_OUT_OF_MEMORY;
 
             // rhp: Ugh, this is ugly...but it works.
             if (fixup_pointer)
               *fixup_pointer = (const char *)*url_name;
           }
--- a/suite/profile/migration/src/nsNetscapeProfileMigratorBase.cpp
+++ b/suite/profile/migration/src/nsNetscapeProfileMigratorBase.cpp
@@ -571,31 +571,31 @@ nsNetscapeProfileMigratorBase::WriteBran
 
   uint32_t count = aPrefs.Length();
   for (uint32_t i = 0; i < count; ++i) {
     PrefBranchStruct* pref = aPrefs.ElementAt(i);
 
     switch (pref->type) {
     case nsIPrefBranch::PREF_STRING:
       branch->SetCharPref(pref->prefName, pref->stringValue);
-      NS_Free(pref->stringValue);
+      free(pref->stringValue);
       pref->stringValue = nullptr;
       break;
     case nsIPrefBranch::PREF_BOOL:
       branch->SetBoolPref(pref->prefName, pref->boolValue);
       break;
     case nsIPrefBranch::PREF_INT:
       branch->SetIntPref(pref->prefName, pref->intValue);
       break;
     default:
       NS_WARNING("Invalid Pref Type in "
                  "nsNetscapeProfileMigratorBase::WriteBranch\n");
       break;
     }
-    NS_Free(pref->prefName);
+    free(pref->prefName);
     pref->prefName = nullptr;
     delete pref;
     pref = nullptr;
   }
   aPrefs.Clear();
 }
 
 nsresult
@@ -799,17 +799,17 @@ nsNetscapeProfileMigratorBase::CopySigna
         srcSigFile->CopyTo(targetSigFile, leafName);
         targetSigFile->Append(leafName);
 
         // now write out the new descriptor
         nsAutoCString descriptorString;
         rv = targetSigFile->GetPersistentDescriptor(descriptorString);
         NS_ENSURE_SUCCESS(rv, rv);
 
-        NS_Free(pref->stringValue);
+        free(pref->stringValue);
         pref->stringValue = ToNewCString(descriptorString);
       }
     }
   }
   return NS_OK;
 }
 
 nsresult
@@ -889,17 +889,17 @@ nsNetscapeProfileMigratorBase::CopyMailF
         RecursiveCopy(sourceMailFolder, targetMailFolder);
         // now we want to make sure the actual directory pref that gets
         // transformed into the new profile's pref.js has the right file
         // location.
         nsAutoCString descriptorString;
         rv = targetMailFolder->GetPersistentDescriptor(descriptorString);
         NS_ENSURE_SUCCESS(rv, rv);
 
-        NS_Free(pref->stringValue);
+        free(pref->stringValue);
         pref->stringValue = ToNewCString(descriptorString);
       }
     }
     else if (StringEndsWith(prefName, NS_LITERAL_CSTRING(".newsrc.file"))) {
       // copy the news RC file into \News. this won't work if the user has
       // different newsrc files for each account I don't know what to do in
       // that situation.
       nsCOMPtr<nsIFile> targetNewsRCFile;
@@ -923,31 +923,31 @@ nsNetscapeProfileMigratorBase::CopyMailF
         srcNewsRCFile->CopyTo(targetNewsRCFile,leafName);
         targetNewsRCFile->Append(leafName);
 
         // now write out the new descriptor
         nsAutoCString descriptorString;
         rv = targetNewsRCFile->GetPersistentDescriptor(descriptorString);
         NS_ENSURE_SUCCESS(rv, rv);
 
-        NS_Free(pref->stringValue);
+        free(pref->stringValue);
         pref->stringValue = ToNewCString(descriptorString);
       }
     }
   }
 
   // Remove all .directory-rel prefs as those might have changed; MailNews
   // will create those prefs again on first use
   for (int32_t i = count; i-- > 0; ) {
     PrefBranchStruct* pref = aMailServers.ElementAt(i);
     nsDependentCString prefName(pref->prefName);
 
     if (StringEndsWith(prefName, NS_LITERAL_CSTRING(".directory-rel"))) {
       if (pref->type == nsIPrefBranch::PREF_STRING)
-        NS_Free(pref->stringValue);
+        free(pref->stringValue);
 
       aMailServers.RemoveElementAt(i);
     }
   }
 
   return NS_OK;
 }