Bug 1376638 - Minimize uses of prmem.h. r=glandium.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 30 Jun 2017 19:05:41 -0700
changeset 402909 b73577b45267675bfdfe3324c8ddb240590f1ab1
parent 402908 8142a8ca666cac6d886cf00ade41df659ba617a5
child 402910 283debe8155accfec5812c66e33384ce217d02c2
child 402924 433a11759a4c687eded12162c29610e6919b5352
push idunknown
push userunknown
push dateunknown
reviewersglandium
bugs1376638
milestone56.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 1376638 - Minimize uses of prmem.h. r=glandium. It's silly to use prmem.h within Firefox code given that in our configuration its functions are just wrappers for malloc() et al. (Indeed, in some places we mix PR_Malloc() with free(), or malloc() with PR_Free().) This patch removes all uses, except for the places where we need to use PR_Free() to free something allocated by another NSPR function; in those cases I've added a comment explaining which function did the allocation.
dom/base/nsJSEnvironment.cpp
dom/file/FileReader.cpp
dom/media/android/AndroidMediaPluginHost.cpp
dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp
dom/media/webrtc/MediaEngineDefault.cpp
dom/plugins/base/nsJSNPRuntime.cpp
dom/plugins/base/nsNPAPIPlugin.cpp
dom/plugins/base/nsNPAPIPluginInstance.cpp
dom/plugins/base/nsNPAPIPluginStreamListener.cpp
dom/plugins/base/nsPluginHost.cpp
dom/plugins/base/nsPluginsDirUnix.cpp
dom/plugins/base/nsPluginsDirUtils.h
dom/plugins/base/nsPluginsDirWin.cpp
dom/xml/nsXMLContentSink.cpp
dom/xslt/xslt/txXPathResultComparator.cpp
dom/xul/nsXULContentSink.cpp
extensions/auth/nsHttpNegotiateAuth.cpp
extensions/pref/autoconfig/src/nsAutoConfig.cpp
extensions/pref/autoconfig/src/nsReadConfig.cpp
extensions/universalchardet/src/base/nsCharSetProber.cpp
extensions/universalchardet/src/base/nsCharSetProber.h
extensions/universalchardet/src/base/nsLatin1Prober.cpp
gfx/vr/VRDisplayClient.cpp
gfx/vr/gfxVROSVR.cpp
gfx/vr/gfxVROculus.cpp
gfx/vr/gfxVROpenVR.cpp
image/decoders/nsJPEGDecoder.cpp
intl/locale/nsCollation.cpp
intl/locale/nsCollationAndroid.cpp
ipc/chromium/src/base/logging.cc
ipc/chromium/src/base/process_util_bsd.cc
ipc/chromium/src/base/process_util_linux.cc
media/webrtc/signaling/gtest/mediaconduit_unittests.cpp
media/webrtc/signaling/test/FakeMediaStreamsImpl.h
mozglue/android/NSSBridge.h
netwerk/base/NetworkActivityMonitor.cpp
netwerk/base/ShutdownLayer.cpp
netwerk/base/TCPFastOpenLayer.cpp
netwerk/base/nsBase64Encoder.cpp
netwerk/cache/nsDiskCacheMap.cpp
netwerk/mime/nsMIMEHeaderParamImpl.cpp
netwerk/protocol/websocket/WebSocketChannel.cpp
netwerk/socket/nsNamedPipeIOLayer.cpp
netwerk/socket/nsSOCKSIOLayer.cpp
parser/htmlparser/nsExpatDriver.cpp
rdf/base/nsRDFContentSink.cpp
rdf/base/nsRDFService.cpp
security/certverifier/NSSCertDBTrustDomain.cpp
security/manager/ssl/nsNSSCertificate.cpp
security/manager/ssl/nsNSSComponent.cpp
security/manager/ssl/nsNSSIOLayer.cpp
security/manager/ssl/nsPKCS12Blob.cpp
security/manager/ssl/nsSmartCardMonitor.cpp
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/system/unixproxy/nsLibProxySettings.cpp
toolkit/xre/nsAppRunner.cpp
uriloader/exthandler/mac/nsDecodeAppleFile.cpp
widget/windows/nsBidiKeyboard.cpp
widget/windows/nsDeviceContextSpecWin.cpp
widget/windows/nsImageClipboard.cpp
widget/windows/nsSound.cpp
widget/windows/nsWindow.cpp
widget/windows/nsWindowGfx.cpp
widget/xremoteclient/XRemoteClient.cpp
xpcom/base/nsTraceRefcnt.cpp
xpcom/io/nsLocalFileUnix.cpp
xpcom/io/nsLocalFileWin.cpp
xpcom/string/nsTextFormatter.cpp
xpcom/threads/nsProcessCommon.cpp
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -46,17 +46,16 @@
 #include "xpcpublic.h"
 
 #include "jsapi.h"
 #include "jswrapper.h"
 #include "js/SliceBudget.h"
 #include "nsIArray.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
-#include "prmem.h"
 #include "WrapperFactory.h"
 #include "nsGlobalWindow.h"
 #include "nsScriptNameSpaceManager.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/MainThreadIdlePeriod.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/dom/DOMException.h"
 #include "mozilla/dom/DOMExceptionBinding.h"
--- a/dom/file/FileReader.cpp
+++ b/dom/file/FileReader.cpp
@@ -318,16 +318,18 @@ FileReader::DoReadData(uint64_t aCount)
   }
   else {
     CheckedInt<uint64_t> size = mDataLen;
     size += aCount;
 
     //Update memory buffer to reflect the contents of the file
     if (!size.isValid() ||
         // PR_Realloc doesn't support over 4GB memory size even if 64-bit OS
+        // XXX: it's likely that this check is unnecessary and the comment is
+        // wrong because we no longer use PR_Realloc outside of NSPR and NSS.
         size.value() > UINT32_MAX ||
         size.value() > mTotal) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     MOZ_DIAGNOSTIC_ASSERT(mFileData);
     MOZ_RELEASE_ASSERT((mDataLen + aCount) <= mTotal);
 
--- a/dom/media/android/AndroidMediaPluginHost.cpp
+++ b/dom/media/android/AndroidMediaPluginHost.cpp
@@ -195,17 +195,17 @@ AndroidMediaPluginHost::AndroidMediaPlug
 
   const char* name = GetOmxLibraryName();
   ALOG("Loading OMX Plugin: %s", name ? name : "nullptr");
   if (name) {
     char *path = PR_GetLibraryFilePathname("libxul.so", (PRFuncPtr) GetOmxLibraryName);
     PRLibrary *lib = nullptr;
     if (path) {
       nsAutoCString libpath(path);
-      PR_Free(path);
+      PR_Free(path);  // PR_GetLibraryFilePathname() uses PR_Malloc().
       int32_t slash = libpath.RFindChar('/');
       if (slash != kNotFound) {
         libpath.Truncate(slash + 1);
         libpath.Append(name);
         lib = PR_LoadLibrary(libpath.get());
       }
     }
     if (!lib)
--- a/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp
+++ b/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp
@@ -61,20 +61,20 @@ FFVPXRuntimeLinker::Init()
                               (PRFuncPtr)&soundtouch::SoundTouch::getVersionId);
   PR_FreeLibraryName(lgpllibsname);
   if (!path) {
     return false;
   }
   nsCOMPtr<nsIFile> xulFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
   if (!xulFile ||
       NS_FAILED(xulFile->InitWithNativePath(nsDependentCString(path)))) {
-    PR_Free(path);
+    PR_Free(path); // PR_GetLibraryFilePathname() uses PR_Malloc().
     return false;
   }
-  PR_Free(path);
+  PR_Free(path); // PR_GetLibraryFilePathname() uses PR_Malloc().
 
   nsCOMPtr<nsIFile> rootDir;
   if (NS_FAILED(xulFile->GetParent(getter_AddRefs(rootDir))) || !rootDir) {
     return false;
   }
   nsAutoCString rootPath;
   if (NS_FAILED(rootDir->GetNativePath(rootPath))) {
     return false;
--- a/dom/media/webrtc/MediaEngineDefault.cpp
+++ b/dom/media/webrtc/MediaEngineDefault.cpp
@@ -6,17 +6,16 @@
 
 #include "nsCOMPtr.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/UniquePtr.h"
 #include "nsILocalFile.h"
 #include "Layers.h"
 #include "ImageContainer.h"
 #include "ImageTypes.h"
-#include "prmem.h"
 #include "nsContentUtils.h"
 #include "MediaStreamGraph.h"
 
 #include "nsIFilePicker.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 
 #ifdef MOZ_WIDGET_ANDROID
@@ -143,17 +142,17 @@ static void AllocateSolidColorFrame(laye
                                     int aY, int aCb, int aCr)
 {
   MOZ_ASSERT(!(aWidth&1));
   MOZ_ASSERT(!(aHeight&1));
   // Allocate a single frame with a solid color
   int yLen = aWidth*aHeight;
   int cbLen = yLen>>2;
   int crLen = cbLen;
-  uint8_t* frame = (uint8_t*) PR_Malloc(yLen+cbLen+crLen);
+  uint8_t* frame = (uint8_t*) malloc(yLen+cbLen+crLen);
   memset(frame, aY, yLen);
   memset(frame+yLen, aCb, cbLen);
   memset(frame+yLen+cbLen, aCr, crLen);
 
   aData.mYChannel = frame;
   aData.mYSize = IntSize(aWidth, aHeight);
   aData.mYStride = aWidth;
   aData.mCbCrStride = aWidth>>1;
@@ -163,17 +162,17 @@ static void AllocateSolidColorFrame(laye
   aData.mPicX = 0;
   aData.mPicY = 0;
   aData.mPicSize = IntSize(aWidth, aHeight);
   aData.mStereoMode = StereoMode::MONO;
 }
 
 static void ReleaseFrame(layers::PlanarYCbCrData& aData)
 {
-  PR_Free(aData.mYChannel);
+  free(aData.mYChannel);
 }
 
 nsresult
 MediaEngineDefaultVideoSource::Start(SourceMediaStream* aStream, TrackID aID,
                                      const PrincipalHandle& aPrincipalHandle)
 {
   if (mState != kAllocated) {
     return NS_ERROR_FAILURE;
--- a/dom/plugins/base/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -17,17 +17,16 @@
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptContext.h"
 #include "nsDOMJSUtils.h"
 #include "nsJSUtils.h"
 #include "nsIDocument.h"
 #include "nsIXPConnect.h"
 #include "xpcpublic.h"
 #include "nsIDOMElement.h"
-#include "prmem.h"
 #include "nsIContent.h"
 #include "nsPluginInstanceOwner.h"
 #include "nsWrapperCacheInlines.h"
 #include "js/GCHashTable.h"
 #include "js/TracingAPI.h"
 #include "mozilla/HashFunctions.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/plugins/PluginAsyncSurrogate.h"
@@ -1039,35 +1038,35 @@ nsJSObjWrapper::NP_Enumerate(NPObject *n
   JSAutoCompartment ac(cx, jsobj);
 
   JS::Rooted<JS::IdVector> ida(cx, JS::IdVector(cx));
   if (!JS_Enumerate(cx, jsobj, &ida)) {
     return false;
   }
 
   *count = ida.length();
-  *idarray = (NPIdentifier *)PR_Malloc(*count * sizeof(NPIdentifier));
+  *idarray = (NPIdentifier*) malloc(*count * sizeof(NPIdentifier));
   if (!*idarray) {
     ThrowJSExceptionASCII(cx, "Memory allocation failed for NPIdentifier!");
     return false;
   }
 
   for (uint32_t i = 0; i < *count; i++) {
     JS::Rooted<JS::Value> v(cx);
     if (!JS_IdToValue(cx, ida[i], &v)) {
-      PR_Free(*idarray);
+      free(*idarray);
       return false;
     }
 
     NPIdentifier id;
     if (v.isString()) {
       JS::Rooted<JSString*> str(cx, v.toString());
       str = JS_AtomizeAndPinJSString(cx, str);
       if (!str) {
-        PR_Free(*idarray);
+        free(*idarray);
         return false;
       }
       id = StringToNPIdentifier(cx, str);
     } else {
       NS_ASSERTION(v.isInt32(),
                    "The element in ida must be either string or int!\n");
       id = IntToNPIdentifier(v.toInt32());
     }
@@ -1494,33 +1493,33 @@ CallNPMethodInternal(JSContext *cx, JS::
   PluginDestructionGuard pdg(npp);
 
   NPVariant npargs_buf[8];
   NPVariant *npargs = npargs_buf;
 
   if (argc > (sizeof(npargs_buf) / sizeof(NPVariant))) {
     // Our stack buffer isn't large enough to hold all arguments,
     // malloc a buffer.
-    npargs = (NPVariant *)PR_Malloc(argc * sizeof(NPVariant));
+    npargs = (NPVariant*) malloc(argc * sizeof(NPVariant));
 
     if (!npargs) {
       ThrowJSExceptionASCII(cx, "Out of memory!");
 
       return false;
     }
   }
 
   // Convert arguments
   uint32_t i;
   for (i = 0; i < argc; ++i) {
     if (!JSValToNPVariant(npp, cx, argv[i], npargs + i)) {
       ThrowJSExceptionASCII(cx, "Error converting jsvals to NPVariants!");
 
       if (npargs != npargs_buf) {
-        PR_Free(npargs);
+        free(npargs);
       }
 
       return false;
     }
   }
 
   NPVariant v;
   VOID_TO_NPVARIANT(v);
@@ -1572,17 +1571,17 @@ CallNPMethodInternal(JSContext *cx, JS::
   }
 
   // Release arguments.
   for (i = 0; i < argc; ++i) {
     _releasevariantvalue(npargs + i);
   }
 
   if (npargs != npargs_buf) {
-    PR_Free(npargs);
+    free(npargs);
   }
 
   if (!ok) {
     // ReportExceptionIfPending returns a return value, which is true
     // if no exception was thrown. In that case, throw our own.
     if (ReportExceptionIfPending(cx))
       ThrowJSExceptionASCII(cx, msg);
 
@@ -1641,17 +1640,17 @@ NPObjWrapper_NewEnumerate(JSContext *cx,
     return false;
 
   JS::Rooted<jsid> id(cx);
   for (uint32_t i = 0; i < length; i++) {
     id = NPIdentifierToJSId(identifiers[i]);
     properties.infallibleAppend(id);
   }
 
-  PR_Free(identifiers);
+  free(identifiers);
   return true;
 }
 
 static bool
 NPObjWrapper_Resolve(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
                      bool *resolvedp)
 {
   if (JSID_IS_SYMBOL(id))
@@ -2011,17 +2010,17 @@ nsJSNPRuntime::OnPluginDestroy(NPP npp)
         }
 #endif
 
         // Force deallocation of plugin objects since the plugin they came
         // from is being torn down.
         if (npobj->_class && npobj->_class->deallocate) {
           npobj->_class->deallocate(npobj);
         } else {
-          PR_Free(npobj);
+          free(npobj);
         }
 
         ::JS_SetPrivate(entry->mJSObj, nullptr);
 
         sNPObjWrappers = tmp;
 
         if (sDelayedReleases && sDelayedReleases->RemoveElement(npobj)) {
           OnWrapperDestroyed();
@@ -2079,28 +2078,28 @@ CreateNPObjectMember(NPP npp, JSContext 
 {
   if (!npobj || !npobj->_class || !npobj->_class->getProperty ||
       !npobj->_class->invoke) {
     ThrowJSExceptionASCII(cx, "Bad NPObject");
 
     return false;
   }
 
-  NPObjectMemberPrivate *memberPrivate =
-    (NPObjectMemberPrivate *)PR_Malloc(sizeof(NPObjectMemberPrivate));
+  NPObjectMemberPrivate* memberPrivate =
+    (NPObjectMemberPrivate*) malloc(sizeof(NPObjectMemberPrivate));
   if (!memberPrivate)
     return false;
 
   // Make sure to clear all members in case something fails here
   // during initialization.
   memset(memberPrivate, 0, sizeof(NPObjectMemberPrivate));
 
   JSObject *memobj = ::JS_NewObject(cx, &sNPObjectMemberClass);
   if (!memobj) {
-    PR_Free(memberPrivate);
+    free(memberPrivate);
     return false;
   }
 
   vp.setObject(*memobj);
 
   ::JS_SetPrivate(memobj, (void *)memberPrivate);
 
   NPIdentifier identifier = JSIdToNPIdentifier(id);
@@ -2165,17 +2164,17 @@ static void
 NPObjectMember_Finalize(JSFreeOp *fop, JSObject *obj)
 {
   NPObjectMemberPrivate *memberPrivate;
 
   memberPrivate = (NPObjectMemberPrivate *)::JS_GetPrivate(obj);
   if (!memberPrivate)
     return;
 
-  PR_Free(memberPrivate);
+  free(memberPrivate);
 }
 
 static bool
 NPObjectMember_Call(JSContext *cx, unsigned argc, JS::Value *vp)
 {
   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
   JS::Rooted<JSObject*> memobj(cx, &args.callee());
   NS_ENSURE_TRUE(memobj, false);
@@ -2195,32 +2194,32 @@ NPObjectMember_Call(JSContext *cx, unsig
   }
 
   NPVariant npargs_buf[8];
   NPVariant *npargs = npargs_buf;
 
   if (args.length() > (sizeof(npargs_buf) / sizeof(NPVariant))) {
     // Our stack buffer isn't large enough to hold all arguments,
     // malloc a buffer.
-    npargs = (NPVariant *)PR_Malloc(args.length() * sizeof(NPVariant));
+    npargs = (NPVariant*) malloc(args.length() * sizeof(NPVariant));
 
     if (!npargs) {
       ThrowJSExceptionASCII(cx, "Out of memory!");
 
       return false;
     }
   }
 
   // Convert arguments
   for (uint32_t i = 0; i < args.length(); ++i) {
     if (!JSValToNPVariant(memberPrivate->npp, cx, args[i], npargs + i)) {
       ThrowJSExceptionASCII(cx, "Error converting jsvals to NPVariants!");
 
       if (npargs != npargs_buf) {
-        PR_Free(npargs);
+        free(npargs);
       }
 
       return false;
     }
   }
 
 
   NPVariant npv;
@@ -2229,17 +2228,17 @@ NPObjectMember_Call(JSContext *cx, unsig
                                   npargs, args.length(), &npv);
 
   // Release arguments.
   for (uint32_t i = 0; i < args.length(); ++i) {
     _releasevariantvalue(npargs + i);
   }
 
   if (npargs != npargs_buf) {
-    PR_Free(npargs);
+    free(npargs);
   }
 
   if (!ok) {
     // ReportExceptionIfPending returns a return value, which is true
     // if no exception was thrown. In that case, throw our own.
     if (ReportExceptionIfPending(cx))
       ThrowJSExceptionASCII(cx, "Error calling method on NPObject!");
 
--- a/dom/plugins/base/nsNPAPIPlugin.cpp
+++ b/dom/plugins/base/nsNPAPIPlugin.cpp
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "base/basictypes.h"
 
 /* This must occur *after* layers/PLayerTransaction.h to avoid typedefs conflicts. */
 #include "mozilla/ArrayUtils.h"
 
 #include "pratom.h"
-#include "prmem.h"
 #include "prenv.h"
 #include "prclist.h"
 
 #include "jsfriendapi.h"
 
 #include "nsPluginHost.h"
 #include "nsNPAPIPlugin.h"
 #include "nsNPAPIPluginInstance.h"
@@ -1168,17 +1167,17 @@ NPObject*
 
   NPPAutoPusher nppPusher(npp);
 
   NPObject *npobj;
 
   if (aClass->allocate) {
     npobj = aClass->allocate(npp, aClass);
   } else {
-    npobj = (NPObject *)PR_Malloc(sizeof(NPObject));
+    npobj = (NPObject*) malloc(sizeof(NPObject));
   }
 
   if (npobj) {
     npobj->_class = aClass;
     npobj->referenceCount = 1;
     NS_LOG_ADDREF(npobj, 1, "BrowserNPObject", sizeof(NPObject));
   }
 
@@ -1232,17 +1231,17 @@ void
     nsNPObjWrapper::OnDestroy(npobj);
 
     NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY,
                    ("Deleting NPObject %p, refcount hit 0\n", npobj));
 
     if (npobj->_class && npobj->_class->deallocate) {
       npobj->_class->deallocate(npobj);
     } else {
-      PR_Free(npobj);
+      free(npobj);
     }
   }
 }
 
 bool
 _invoke(NPP npp, NPObject* npobj, NPIdentifier method, const NPVariant *args,
         uint32_t argCount, NPVariant *result)
 {
@@ -1643,17 +1642,17 @@ void
     break;
   case NPVariantType_String :
     {
       const NPString *s = &NPVARIANT_TO_STRING(*variant);
 
       if (s->UTF8Characters) {
 #if defined(MOZ_MEMORY_WINDOWS)
         if (malloc_usable_size((void *)s->UTF8Characters) != 0) {
-          PR_Free((void *)s->UTF8Characters);
+          free((void*)s->UTF8Characters);
         } else {
           void *p = (void *)s->UTF8Characters;
           DWORD nheaps = 0;
           AutoTArray<HANDLE, 50> heaps;
           nheaps = GetProcessHeaps(0, heaps.Elements());
           heaps.AppendElements(nheaps);
           GetProcessHeaps(nheaps, heaps.Elements());
           for (DWORD i = 0; i < nheaps; i++) {
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -6,17 +6,16 @@
 #include "mozilla/DebugOnly.h"
 
 #ifdef MOZ_WIDGET_ANDROID
 // For ScreenOrientation.h and Hal.h
 #include "base/basictypes.h"
 #endif
 
 #include "mozilla/Logging.h"
-#include "prmem.h"
 #include "nscore.h"
 #include "prenv.h"
 
 #include "nsNPAPIPluginInstance.h"
 #include "nsNPAPIPlugin.h"
 #include "nsNPAPIPluginStreamListener.h"
 #include "nsPluginHost.h"
 #include "nsPluginLogging.h"
@@ -162,17 +161,17 @@ nsNPAPIPluginInstance::~nsNPAPIPluginIns
 {
   PLUGIN_LOG(PLUGIN_LOG_BASIC, ("nsNPAPIPluginInstance dtor: this=%p\n",this));
 
 #ifdef MOZ_WIDGET_ANDROID
   sPluginNPPMap.erase(&mNPP);
 #endif
 
   if (mMIMEType) {
-    PR_Free((void *)mMIMEType);
+    free(mMIMEType);
     mMIMEType = nullptr;
   }
 
   if (!mCachedParamValues || !mCachedParamNames) {
     return;
   }
   MOZ_ASSERT(mCachedParamValues && mCachedParamNames);
 
--- a/dom/plugins/base/nsNPAPIPluginStreamListener.cpp
+++ b/dom/plugins/base/nsNPAPIPluginStreamListener.cpp
@@ -1,16 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsNPAPIPluginStreamListener.h"
 #include "plstr.h"
-#include "prmem.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsIFile.h"
 #include "nsNetUtil.h"
 #include "nsPluginHost.h"
 #include "nsNPAPIPlugin.h"
 #include "nsPluginLogging.h"
 #include "nsPluginStreamListenerPeer.h"
@@ -164,17 +163,17 @@ nsNPAPIPluginStreamListener::~nsNPAPIPlu
   // For those cases when NewStream is never called, we still may need
   // to fire a notification callback. Return network error as fallback
   // reason because for other cases, notify should have already been
   // called for other reasons elsewhere.
   CallURLNotify(NPRES_NETWORK_ERR);
   
   // lets get rid of the buffer
   if (mStreamBuffer) {
-    PR_Free(mStreamBuffer);
+    free(mStreamBuffer);
     mStreamBuffer=nullptr;
   }
   
   if (mNotifyURL)
     PL_strfree(mNotifyURL);
   
   if (mResponseHeaderBuf)
     PL_strfree(mResponseHeaderBuf);
@@ -495,17 +494,17 @@ nsNPAPIPluginStreamListener::OnDataAvail
     mStreamBufferSize = std::max(length, contentLength);
     
     // Limit the size of the initial buffer to MAX_PLUGIN_NECKO_BUFFER
     // (16k). This buffer will grow if needed, as in the case where
     // we're getting data faster than the plugin can process it.
     mStreamBufferSize = std::min(mStreamBufferSize,
                                uint32_t(MAX_PLUGIN_NECKO_BUFFER));
     
-    mStreamBuffer = (char*) PR_Malloc(mStreamBufferSize);
+    mStreamBuffer = (char*) malloc(mStreamBufferSize);
     if (!mStreamBuffer)
       return NS_ERROR_OUT_OF_MEMORY;
   }
   
   // prepare NPP_ calls params
   NPP npp;
   mInst->GetNPP(&npp);
   
@@ -541,17 +540,17 @@ nsNPAPIPluginStreamListener::OnDataAvail
         // We're in the ::OnDataAvailable() call that we might get
         // after suspending a request, or we suspended the request
         // from within this ::OnDataAvailable() call while there's
         // still data in the input, or we have resumed a previously
         // suspended request and our buffer is already full, and we
         // don't have enough space to store what we got off the network.
         // Reallocate our internal buffer.
         mStreamBufferSize = mStreamBufferByteCount + length;
-        char *buf = (char*)PR_Realloc(mStreamBuffer, mStreamBufferSize);
+        char* buf = (char*) realloc(mStreamBuffer, mStreamBufferSize);
         if (!buf)
           return NS_ERROR_OUT_OF_MEMORY;
         
         mStreamBuffer = buf;
       }
 
       uint32_t bytesToRead =
       std::min(length, mStreamBufferSize - mStreamBufferByteCount);
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -6,17 +6,16 @@
 /* nsPluginHost.cpp - top-level plugin management code */
 
 #include "nscore.h"
 #include "nsPluginHost.h"
 
 #include <cstdlib>
 #include <stdio.h>
 #include "prio.h"
-#include "prmem.h"
 #include "nsNPAPIPlugin.h"
 #include "nsNPAPIPluginStreamListener.h"
 #include "nsNPAPIPluginInstance.h"
 #include "nsPluginInstanceOwner.h"
 #include "nsObjectLoadingContent.h"
 #include "nsIHTTPHeaderListener.h"
 #include "nsIHttpHeaderVisitor.h"
 #include "nsIObserverService.h"
--- a/dom/plugins/base/nsPluginsDirUnix.cpp
+++ b/dom/plugins/base/nsPluginsDirUnix.cpp
@@ -3,17 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsNPAPIPlugin.h"
 #include "nsNPAPIPluginInstance.h"
 #include "nsIMemory.h"
 #include "nsPluginsDir.h"
 #include "nsPluginsDirUtils.h"
-#include "prmem.h"
 #include "prenv.h"
 #include "prerror.h"
 #include "prio.h"
 #include <sys/stat.h>
 #include "nsString.h"
 #include "nsIFile.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
@@ -399,19 +398,22 @@ nsresult nsPluginFile::FreePluginInfo(ns
 
         if (info.fMimeDescriptionArray[i] != nullptr)
             PL_strfree(info.fMimeDescriptionArray[i]);
 
         if (info.fExtensionArray[i] != nullptr)
             PL_strfree(info.fExtensionArray[i]);
     }
 
-    PR_FREEIF(info.fMimeTypeArray);
-    PR_FREEIF(info.fMimeDescriptionArray);
-    PR_FREEIF(info.fExtensionArray);
+    free(info.fMimeTypeArray);
+    info.fMimeTypeArray = nullptr;
+    free(info.fMimeDescriptionArray);
+    info.fMimeDescriptionArray = nullptr;
+    free(info.fExtensionArray);
+    info.fExtensionArray = nullptr;
 
     if (info.fFullPath != nullptr)
         PL_strfree(info.fFullPath);
 
     if (info.fFileName != nullptr)
         PL_strfree(info.fFileName);
 
     if (info.fVersion != nullptr)
--- a/dom/plugins/base/nsPluginsDirUtils.h
+++ b/dom/plugins/base/nsPluginsDirUtils.h
@@ -3,17 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsPluginsDirUtils_h___
 #define nsPluginsDirUtils_h___
 
 #include "nsPluginsDir.h"
 #include "nsTArray.h"
-#include "prmem.h"
 
 ///////////////////////////////////////////////////////////////////////////////
 // Output format from NPP_GetMIMEDescription: "...mime type[;version]:[extension]:[desecription];..."
 // The ambiguity of mime description could cause the browser fail to parse the MIME types 
 // correctly.
 // E.g. "mime type::desecription;" // correct w/o ext 
 //      "mime type:desecription;"  // wrong w/o ext 
 //
@@ -62,28 +61,28 @@ ParsePluginMimeDescription(const char *m
             mimeTypeVariantCount++;
         }
     }
 
     // fill out info structure
     if (mimeTypeVariantCount) {
         info.fVariantCount         = mimeTypeVariantCount;
         // we can do these 3 mallocs at once, later on code cleanup
-        info.fMimeTypeArray        = (char **)PR_Malloc(mimeTypeVariantCount * sizeof(char *));
-        info.fMimeDescriptionArray = (char **)PR_Malloc(mimeTypeVariantCount * sizeof(char *));
-        info.fExtensionArray       = (char **)PR_Malloc(mimeTypeVariantCount * sizeof(char *));
+        info.fMimeTypeArray        = (char**) malloc(mimeTypeVariantCount * sizeof(char*));
+        info.fMimeDescriptionArray = (char**) malloc(mimeTypeVariantCount * sizeof(char*));
+        info.fExtensionArray       = (char**) malloc(mimeTypeVariantCount * sizeof(char*));
 
         int j,i;
         for (j = i = 0; i < mimeTypeVariantCount; i++) {
             // the order is important, do not change it
            // we can get rid of PL_strdup here, later on code cleanup
             info.fMimeTypeArray[i]        =  PL_strdup(tmpMimeTypeArr.ElementAt(j++));
             info.fExtensionArray[i]       =  PL_strdup(tmpMimeTypeArr.ElementAt(j++));
             info.fMimeDescriptionArray[i] =  PL_strdup(tmpMimeTypeArr.ElementAt(j++));
         }
         rv = NS_OK;
     }
     if (mdescDup)
-        PR_Free(mdescDup);
+        PL_strfree(mdescDup);
     return rv;
 }
 
 #endif /* nsPluginsDirUtils_h___ */
--- a/dom/plugins/base/nsPluginsDirWin.cpp
+++ b/dom/plugins/base/nsPluginsDirWin.cpp
@@ -13,17 +13,16 @@
 
 #include "mozilla/ArrayUtils.h" // ArrayLength
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Printf.h"
 
 #include "nsPluginsDir.h"
 #include "prlink.h"
 #include "plstr.h"
-#include "prmem.h"
 
 #include "windows.h"
 #include "winbase.h"
 
 #include "nsString.h"
 #include "nsIFile.h"
 #include "nsUnicharUtils.h"
 
@@ -146,17 +145,17 @@ static char** MakeStringArray(uint32_t v
   // type array. Plugins are not explicitely required to match
   // this number in two other arrays: file extention array and mime
   // description array, and some of them actually don't. 
   // We should handle such situations gracefully
 
   if ((variants <= 0) || !data)
     return nullptr;
 
-  char ** array = (char **)PR_Calloc(variants, sizeof(char *));
+  char** array = (char**) calloc(variants, sizeof(char *));
   if (!array)
     return nullptr;
 
   char * start = data;
 
   for (uint32_t i = 0; i < variants; i++) {
     char * p = PL_strchr(start, '|');
     if (p)
@@ -184,17 +183,17 @@ static void FreeStringArray(uint32_t var
     return;
 
   for (uint32_t i = 0; i < variants; i++) {
     if (array[i]) {
       PL_strfree(array[i]);
       array[i] = nullptr;
     }
   }
-  PR_Free(array);
+  free(array);
 }
 
 static bool CanLoadPlugin(char16ptr_t aBinaryPath)
 {
 #if defined(_M_IX86) || defined(_M_X64) || defined(_M_IA64)
   bool canLoad = false;
 
   HANDLE file = CreateFileW(aBinaryPath, GENERIC_READ,
@@ -358,17 +357,17 @@ nsresult nsPluginFile::GetPluginInfo(nsP
   if (NS_FAILED(rv = mPlugin->GetLeafName(fileName)))
     return rv;
 
   LPCWSTR lpFilepath = fullPath.get();
 
   versionsize = ::GetFileVersionInfoSizeW(lpFilepath, &zerome);
 
   if (versionsize > 0)
-    verbuf = PR_Malloc(versionsize);
+    verbuf = malloc(versionsize);
   if (!verbuf)
     return NS_ERROR_OUT_OF_MEMORY;
 
   if (::GetFileVersionInfoW(lpFilepath, 0, versionsize, verbuf))
   {
     // TODO: get appropriately-localized info from plugin file
     UINT lang = 1033; // language = English, 0x409
     UINT cp = 1252;   // codepage = Western, 0x4E4
@@ -391,17 +390,17 @@ nsresult nsPluginFile::GetPluginInfo(nsP
     PL_strfree(mimeType);
     PL_strfree(mimeDescription);
     PL_strfree(extensions);
   }
   else {
     rv = NS_ERROR_FAILURE;
   }
 
-  PR_Free(verbuf);
+  free(verbuf);
 
   return rv;
 }
 
 nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
 {
   if (info.fName)
     PL_strfree(info.fName);
--- a/dom/xml/nsXMLContentSink.cpp
+++ b/dom/xml/nsXMLContentSink.cpp
@@ -26,17 +26,16 @@
 #include "nsContentUtils.h"
 #include "nsIScriptContext.h"
 #include "nsNameSpaceManager.h"
 #include "nsIServiceManager.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIContentViewer.h"
 #include "prtime.h"
 #include "mozilla/Logging.h"
-#include "prmem.h"
 #include "nsRect.h"
 #include "nsIWebNavigation.h"
 #include "nsIScriptElement.h"
 #include "nsStyleLinkElement.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsICookieService.h"
 #include "nsIPrompt.h"
--- a/dom/xslt/xslt/txXPathResultComparator.cpp
+++ b/dom/xslt/xslt/txXPathResultComparator.cpp
@@ -5,17 +5,16 @@
 
 #include "mozilla/FloatingPoint.h"
 
 #include "txXPathResultComparator.h"
 #include "txExpr.h"
 #include "txCore.h"
 #include "nsCollationCID.h"
 #include "nsIServiceManager.h"
-#include "prmem.h"
 
 #define kAscending (1<<0)
 #define kUpperFirst (1<<1)
 
 txResultStringComparator::txResultStringComparator(bool aAscending,
                                                    bool aUpperFirst,
                                                    const nsString& aLanguage)
 {
@@ -155,19 +154,19 @@ txResultStringComparator::StringValue::S
                                                        mCaseKey(0),
                                                        mLength(0),
                                                        mCaseLength(0)
 {
 }
 
 txResultStringComparator::StringValue::~StringValue()
 {
-    PR_Free(mKey);
+    free(mKey);
     if (mCaseLength > 0)
-        PR_Free((uint8_t*)mCaseKey);
+        free(mCaseKey);
     else
         delete (nsString*)mCaseKey;
 }
 
 txResultNumberComparator::txResultNumberComparator(bool aAscending)
 {
     mAscending = aAscending ? 1 : -1;
 }
--- a/dom/xul/nsXULContentSink.cpp
+++ b/dom/xul/nsXULContentSink.cpp
@@ -37,17 +37,16 @@
 #include "nsIScriptSecurityManager.h"
 #include "nsLayoutCID.h"
 #include "nsNetUtil.h"
 #include "nsRDFCID.h"
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
 #include "nsXULElement.h"
 #include "mozilla/Logging.h"
-#include "prmem.h"
 #include "nsCRT.h"
 
 #include "nsXULPrototypeDocument.h"     // XXXbe temporary
 #include "mozilla/css/Loader.h"
 
 #include "nsUnicharUtils.h"
 #include "nsGkAtoms.h"
 #include "nsContentUtils.h"
--- a/extensions/auth/nsHttpNegotiateAuth.cpp
+++ b/extensions/auth/nsHttpNegotiateAuth.cpp
@@ -583,17 +583,17 @@ nsHttpNegotiateAuth::GenerateCredentials
     // 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);
 
-    PR_Free(encoded_token);
+    PR_Free(encoded_token); // PL_Base64Encode() uses PR_Malloc().
     return rv;
 }
 
 bool
 nsHttpNegotiateAuth::TestBoolPref(const char *pref)
 {
     nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
     if (!prefs)
--- a/extensions/pref/autoconfig/src/nsAutoConfig.cpp
+++ b/extensions/pref/autoconfig/src/nsAutoConfig.cpp
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsAutoConfig.h"
 #include "nsIURI.h"
 #include "nsIHttpChannel.h"
 #include "nsIFileStreams.h"
 #include "nsThreadUtils.h"
 #include "nsAppDirectoryServiceDefs.h"
-#include "prmem.h"
 #include "nsIObserverService.h"
 #include "nsLiteralString.h"
 #include "nsIPromptService.h"
 #include "nsIServiceManager.h"
 #include "nsIStringBundle.h"
 #include "nsContentUtils.h"
 #include "nsCRT.h"
 #include "nsNetCID.h"
@@ -409,28 +408,28 @@ nsresult nsAutoConfig::evaluateLocalFile
     
     rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), file);
     if (NS_FAILED(rv)) 
         return rv;
         
     int64_t fileSize;
     file->GetFileSize(&fileSize);
     uint32_t fs = fileSize; // Converting 64 bit structure to unsigned int
-    char *buf = (char *)PR_Malloc(fs * sizeof(char));
-    if (!buf) 
+    char* buf = (char*) malloc(fs * sizeof(char));
+    if (!buf)
         return NS_ERROR_OUT_OF_MEMORY;
 
     uint32_t amt = 0;
     rv = inStr->Read(buf, fs, &amt);
     if (NS_SUCCEEDED(rv)) {
       EvaluateAdminConfigScript(buf, fs, nullptr, false, 
                                 true, false);
     }
     inStr->Close();
-    PR_Free(buf);
+    free(buf);
     return rv;
 }
 
 nsresult nsAutoConfig::writeFailoverFile()
 {
     nsresult rv;
     nsCOMPtr<nsIFile> failoverFile; 
     nsCOMPtr<nsIOutputStream> outStr;
--- a/extensions/pref/autoconfig/src/nsReadConfig.cpp
+++ b/extensions/pref/autoconfig/src/nsReadConfig.cpp
@@ -14,17 +14,16 @@
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "nsIPromptService.h"
 #include "nsIServiceManager.h"
 #include "nsIStringBundle.h"
 #include "nsToolkitCompsCID.h"
 #include "nsXPIDLString.h"
 #include "nsNetUtil.h"
-#include "prmem.h"
 #include "nsString.h"
 #include "nsCRT.h"
 #include "nspr.h"
 #include "nsXULAppAPI.h"
 #include "nsContentUtils.h"
 
 extern mozilla::LazyLogModule MCD;
 
@@ -267,35 +266,35 @@ nsresult nsReadConfig::openAndEvaluateJS
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     uint64_t fs64;
     uint32_t amt = 0;
     rv = inStr->Available(&fs64);
     if (NS_FAILED(rv))
         return rv;
-    // PR_Malloc dones't support over 4GB
+    // This used to use PR_Malloc(), which doesn't support over 4GB.
     if (fs64 > UINT32_MAX)
       return NS_ERROR_FILE_TOO_BIG;
     uint32_t fs = (uint32_t)fs64;
 
-    char *buf = (char *)PR_Malloc(fs * sizeof(char));
-    if (!buf) 
+    char* buf = (char*) malloc(fs * sizeof(char));
+    if (!buf)
         return NS_ERROR_OUT_OF_MEMORY;
 
     rv = inStr->Read(buf, (uint32_t)fs, &amt);
     NS_ASSERTION((amt == fs), "failed to read the entire configuration file!!");
     if (NS_SUCCEEDED(rv)) {
         if (obscureValue > 0) {
 
             // Unobscure file by subtracting some value from every char. 
             for (uint32_t i = 0; i < amt; i++)
                 buf[i] -= obscureValue;
         }
         rv = EvaluateAdminConfigScript(buf, amt, aFileName,
                                        false, true,
                                        isEncoded ? true:false);
     }
     inStr->Close();
-    PR_Free(buf);
-    
+    free(buf);
+
     return rv;
 }
--- a/extensions/universalchardet/src/base/nsCharSetProber.cpp
+++ b/extensions/universalchardet/src/base/nsCharSetProber.cpp
@@ -1,24 +1,23 @@
 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  
 #include "nsCharSetProber.h"
-#include "prmem.h"
 
 //This filter applies to all scripts which do not use English characters
 bool nsCharSetProber::FilterWithoutEnglishLetters(const char* aBuf, uint32_t aLen, char** newBuf, uint32_t& newLen)
 {
   char *newptr;
   char *prevPtr, *curPtr;
   
   bool meetMSB = false;   
-  newptr = *newBuf = (char*)PR_Malloc(aLen);
+  newptr = *newBuf = (char*)malloc(aLen);
   if (!newptr)
     return false;
 
   for (curPtr = prevPtr = (char*)aBuf; curPtr < aBuf+aLen; curPtr++)
   {
     if (*curPtr & 0x80)
     {
       meetMSB = true;
@@ -49,17 +48,17 @@ bool nsCharSetProber::FilterWithoutEngli
 //This filter applies to all scripts which contain both English characters and upper ASCII characters.
 bool nsCharSetProber::FilterWithEnglishLetters(const char* aBuf, uint32_t aLen, char** newBuf, uint32_t& newLen)
 {
   //do filtering to reduce load to probers
   char *newptr;
   char *prevPtr, *curPtr;
   bool isInTag = false;
 
-  newptr = *newBuf = (char*)PR_Malloc(aLen);
+  newptr = *newBuf = (char*)malloc(aLen);
   if (!newptr)
     return false;
 
   for (curPtr = prevPtr = (char*)aBuf; curPtr < aBuf+aLen; curPtr++)
   {
     if (*curPtr == '>')
       isInTag = false;
     else if (*curPtr == '<')
--- a/extensions/universalchardet/src/base/nsCharSetProber.h
+++ b/extensions/universalchardet/src/base/nsCharSetProber.h
@@ -27,16 +27,16 @@ public:
   virtual float     GetConfidence(void) = 0;
 
 #ifdef DEBUG_chardet
   virtual void  DumpStatus() {};
 #endif
 
   // Helper functions used in the Latin1 and Group probers.
   // both functions Allocate a new buffer for newBuf. This buffer should be 
-  // freed by the caller using PR_FREEIF.
+  // freed by the caller using free().
   // Both functions return false in case of memory allocation failure.
   static bool FilterWithoutEnglishLetters(const char* aBuf, uint32_t aLen, char** newBuf, uint32_t& newLen);
   static bool FilterWithEnglishLetters(const char* aBuf, uint32_t aLen, char** newBuf, uint32_t& newLen);
 
 };
 
 #endif /* nsCharSetProber_h__ */
--- a/extensions/universalchardet/src/base/nsLatin1Prober.cpp
+++ b/extensions/universalchardet/src/base/nsLatin1Prober.cpp
@@ -1,15 +1,14 @@
 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsLatin1Prober.h"
-#include "prmem.h"
 #include <stdio.h>
 
 #define UDF    0        // undefined
 #define OTH    1        //other
 #define ASC    2        // ascii capital letter
 #define ASS    3        // ascii small letter
 #define ACV    4        // accent capital vowel
 #define ACO    5        // accent capital other
@@ -101,17 +100,17 @@ nsProbingState nsLatin1Prober::HandleDat
       mState = eNotMe;
       break;
     }
     mFreqCounter[freq]++;
     mLastCharClass = charClass;
   }
 
   if (newBuf1 != aBuf)
-    PR_FREEIF(newBuf1);
+    free(newBuf1);
 
   return mState;
 }
 
 float nsLatin1Prober::GetConfidence(void)
 {
   if (mState == eNotMe)
     return 0.01f;
--- a/gfx/vr/VRDisplayClient.cpp
+++ b/gfx/vr/VRDisplayClient.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <math.h>
 
 #include "prlink.h"
-#include "prmem.h"
 #include "prenv.h"
 #include "gfxPrefs.h"
 #include "nsString.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Unused.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIScreenManager.h"
 
@@ -136,9 +135,9 @@ VRDisplayClient::UpdateSubmitFrameResult
 {
   mSubmitFrameResult = aResult;
 }
 
 void
 VRDisplayClient::GetSubmitFrameResult(VRSubmitFrameResultInfo& aResult)
 {
   aResult = mSubmitFrameResult;
-}
\ No newline at end of file
+}
--- a/gfx/vr/gfxVROSVR.cpp
+++ b/gfx/vr/gfxVROSVR.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <math.h>
 
 #include "prlink.h"
-#include "prmem.h"
 #include "prenv.h"
 #include "gfxPrefs.h"
 #include "nsString.h"
 #include "mozilla/Preferences.h"
 
 #include "mozilla/gfx/Quaternion.h"
 
 #ifdef XP_WIN
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -6,17 +6,16 @@
 #ifndef XP_WIN
 #error "Oculus 1.3 runtime support only available for Windows"
 #endif
 
 #include <math.h>
 
 
 #include "prlink.h"
-#include "prmem.h"
 #include "prenv.h"
 #include "gfxPrefs.h"
 #include "nsString.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/gfx/DeviceManagerDx.h"
 #include "ipc/VRLayerParent.h"
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <math.h>
 
 #include "prlink.h"
-#include "prmem.h"
 #include "prenv.h"
 #include "gfxPrefs.h"
 #include "nsString.h"
 #include "mozilla/Preferences.h"
 
 #include "mozilla/gfx/Quaternion.h"
 
 #ifdef XP_WIN
--- a/image/decoders/nsJPEGDecoder.cpp
+++ b/image/decoders/nsJPEGDecoder.cpp
@@ -104,17 +104,18 @@ nsJPEGDecoder::nsJPEGDecoder(RasterImage
 }
 
 nsJPEGDecoder::~nsJPEGDecoder()
 {
   // Step 8: Release JPEG decompression object
   mInfo.src = nullptr;
   jpeg_destroy_decompress(&mInfo);
 
-  PR_FREEIF(mBackBuffer);
+  free(mBackBuffer);
+  mBackBuffer = nullptr;
   if (mTransform) {
     qcms_transform_release(mTransform);
   }
   if (mInProfile) {
     qcms_profile_release(mInProfile);
   }
 
   MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
@@ -899,17 +900,17 @@ fill_input_buffer (j_decompress_ptr jd)
     // Check for malformed MARKER segment lengths, before allocating space
     // for it
     if (new_backtrack_buflen > MAX_JPEG_MARKER_LENGTH) {
       my_error_exit((j_common_ptr)(&decoder->mInfo));
     }
 
     // Round up to multiple of 256 bytes.
     const size_t roundup_buflen = ((new_backtrack_buflen + 255) >> 8) << 8;
-    JOCTET* buf = (JOCTET*)PR_REALLOC(decoder->mBackBuffer, roundup_buflen);
+    JOCTET* buf = (JOCTET*) realloc(decoder->mBackBuffer, roundup_buflen);
     // Check for OOM
     if (!buf) {
       decoder->mInfo.err->msg_code = JERR_OUT_OF_MEMORY;
       my_error_exit((j_common_ptr)(&decoder->mInfo));
     }
     decoder->mBackBuffer = buf;
     decoder->mBackBufferSize = roundup_buflen;
   }
--- a/intl/locale/nsCollation.cpp
+++ b/intl/locale/nsCollation.cpp
@@ -1,16 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsCollation.h"
 #include "nsIServiceManager.h"
-#include "prmem.h"
 #include "nsString.h"
 
 NS_IMPL_ISUPPORTS(nsCollation, nsICollation)
 
 nsCollation::nsCollation()
   : mInit(false)
   , mHasCollator(false)
   , mLastStrength(-1)
@@ -137,18 +136,18 @@ nsCollation::AllocateRawSortKey(int32_t 
 
   uint32_t stringInLen = stringIn.Length();
 
   const UChar* str = (const UChar*)stringIn.BeginReading();
 
   int32_t keyLength = ucol_getSortKey(mCollatorICU, str, stringInLen, nullptr, 0);
   NS_ENSURE_TRUE((stringInLen == 0 || keyLength > 0), NS_ERROR_FAILURE);
 
-  // Since key is freed elsewhere with PR_Free, allocate with PR_Malloc.
-  uint8_t* newKey = (uint8_t*)PR_Malloc(keyLength + 1);
+  // Since key is freed elsewhere with free, allocate with malloc.
+  uint8_t* newKey = (uint8_t*)malloc(keyLength + 1);
   if (!newKey) {
       return NS_ERROR_OUT_OF_MEMORY;
   }
 
   keyLength = ucol_getSortKey(mCollatorICU, str, stringInLen, newKey, keyLength + 1);
   NS_ENSURE_TRUE((stringInLen == 0 || keyLength > 0), NS_ERROR_FAILURE);
 
   *key = newKey;
--- a/intl/locale/nsCollationAndroid.cpp
+++ b/intl/locale/nsCollationAndroid.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsCollation.h"
 #include "nsCOMPtr.h"
 #include "nsUnicharUtils.h"
-#include "prmem.h"
 
 #include  <string.h>
 
 nsCollation::nsCollation()
 {
 }
 
 nsCollation::~nsCollation()
@@ -58,17 +57,17 @@ nsCollation::AllocateRawSortKey(int32_t 
 
   nsAutoString stringNormalized(stringIn);
   if (strength != kCollationCaseSensitive) {
     ToLowerCase(stringNormalized);
   }
 
   NS_ConvertUTF16toUTF8 str(stringNormalized);
   size_t len = str.Length() + 1;
-  void *buffer = PR_Malloc(len);
+  void* buffer = malloc(len);
   memcpy(buffer, str.get(), len);
   *key = (uint8_t *)buffer;
   *outLen = len;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/ipc/chromium/src/base/logging.cc
+++ b/ipc/chromium/src/base/logging.cc
@@ -1,16 +1,15 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #include "base/logging.h"
-#include "prmem.h"
 #include "base/string_util.h"
 #include "nsXPCOM.h"
 #include "mozilla/Move.h"
 
 namespace mozilla {
 
 Logger::~Logger()
 {
--- a/ipc/chromium/src/base/process_util_bsd.cc
+++ b/ipc/chromium/src/base/process_util_bsd.cc
@@ -76,19 +76,19 @@ bool LaunchApp(const std::vector<std::st
   char **environ = PR_DuplicateEnvironment();
   while(environ[pos] != NULL) {
     std::string varString = environ[pos];
     std::string varName = varString.substr(0, varString.find_first_of('='));
     std::string varValue = varString.substr(varString.find_first_of('=') + 1);
     if (combined_env_vars.find(varName) == combined_env_vars.end()) {
       combined_env_vars[varName] = varValue;
     }
-    PR_Free(environ[pos++]);
+    PR_Free(environ[pos++]); // PR_DuplicateEnvironment() uses PR_Malloc().
   }
-  PR_Free(environ);
+  PR_Free(environ); // PR_DuplicateEnvironment() uses PR_Malloc().
   int varsLen = combined_env_vars.size() + 1;
 
   char** vars = new char*[varsLen];
   int i = 0;
   for (environment_map::const_iterator it = combined_env_vars.begin();
        it != combined_env_vars.end(); ++it) {
     std::string entry(it->first);
     entry += "=";
--- a/ipc/chromium/src/base/process_util_linux.cc
+++ b/ipc/chromium/src/base/process_util_linux.cc
@@ -17,17 +17,16 @@
 #include "base/eintr_wrapper.h"
 #include "base/file_util.h"
 #include "base/logging.h"
 #include "base/string_util.h"
 #include "nsLiteralString.h"
 #include "mozilla/UniquePtr.h"
 
 #include "prenv.h"
-#include "prmem.h"
 
 #ifdef MOZ_WIDGET_GONK
 /*
  * AID_APP is the first application UID used by Android. We're using
  * it as our unprivilegied UID.  This ensure the UID used is not
  * shared with any other processes than our own childs.
  */
 # include <private/android_filesystem_config.h>
@@ -59,42 +58,42 @@ namespace base {
 class EnvironmentEnvp
 {
 public:
   EnvironmentEnvp()
     : mEnvp(PR_DuplicateEnvironment()) {}
 
   explicit EnvironmentEnvp(const environment_map &em)
   {
-    mEnvp = (char **)PR_Malloc(sizeof(char *) * (em.size() + 1));
+    mEnvp = (char**) malloc(sizeof(char *) * (em.size() + 1));
     if (!mEnvp) {
       return;
     }
     char **e = mEnvp;
     for (environment_map::const_iterator it = em.begin();
          it != em.end(); ++it, ++e) {
       std::string str = it->first;
       str += "=";
       str += it->second;
       size_t len = str.length() + 1;
-      *e = static_cast<char*>(PR_Malloc(len));
+      *e = static_cast<char*>(malloc(len));
       memcpy(*e, str.c_str(), len);
     }
     *e = NULL;
   }
 
   ~EnvironmentEnvp()
   {
     if (!mEnvp) {
       return;
     }
     for (char **e = mEnvp; *e; ++e) {
-      PR_Free(*e);
+      free(*e);
     }
-    PR_Free(mEnvp);
+    free(mEnvp);
   }
 
   char * const *AsEnvp() { return mEnvp; }
 
   void ToMap(environment_map &em)
   {
     if (!mEnvp) {
       return;
--- a/media/webrtc/signaling/gtest/mediaconduit_unittests.cpp
+++ b/media/webrtc/signaling/gtest/mediaconduit_unittests.cpp
@@ -13,17 +13,16 @@ using namespace std;
 
 #include "mozilla/SyncRunnable.h"
 #include "mozilla/UniquePtr.h"
 #include <MediaConduitInterface.h>
 #include "nsIEventTarget.h"
 #include "nsThreadUtils.h"
 #include "runnable_utils.h"
 #include "signaling/src/common/EncodingConstraints.h"
-#include "prmem.h"
 
 #define GTEST_HAS_RTTI 0
 #include "gtest/gtest.h"
 
 //Video Frame Color
 const int COLOR = 0x80; //Gray
 
 //MWC RNG of George Marsaglia
@@ -780,26 +779,26 @@ class TransportConduitTest : public ::te
     ASSERT_EQ(mozilla::kMediaConduitNoError, err);
     err = mVideoSession->StartTransmitting();
     ASSERT_EQ(mozilla::kMediaConduitNoError, err);
 
     // Send one frame.
     MOZ_ASSERT(!(orig_width & 1));
     MOZ_ASSERT(!(orig_height & 1));
     int len = ((orig_width * orig_height) * 3 / 2);
-    uint8_t* frame = (uint8_t*) PR_MALLOC(len);
+    uint8_t* frame = (uint8_t*) malloc(len);
 
     memset(frame, COLOR, len);
     mVideoSession->SendVideoFrame((unsigned char*)frame,
                                   len,
                                   orig_width,
                                   orig_height,
                                   mozilla::kVideoI420,
                                   0);
-    PR_Free(frame);
+    free(frame);
 
     // Get the new resolution as adjusted by the max-fs constraint.
     *new_width = mVideoSession->SendingWidth();
     *new_height = mVideoSession->SendingHeight();
   }
 
   void TestVideoConduitMaxFs()
   {
--- a/media/webrtc/signaling/test/FakeMediaStreamsImpl.h
+++ b/media/webrtc/signaling/test/FakeMediaStreamsImpl.h
@@ -174,17 +174,17 @@ Fake_VideoStreamSource::Notify(nsITimer*
 
   RefPtr<mozilla::layers::PlanarYCbCrImage> image = new
     mozilla::layers::PlanarYCbCrImage(&bin);
 
   const uint8_t lumaBpp = 8;
   const uint8_t chromaBpp = 4;
 
   int len = ((WIDTH * HEIGHT) * 3 / 2);
-  uint8_t* frame = (uint8_t*) PR_Malloc(len);
+  uint8_t* frame = (uint8_t*) malloc(len);
   memset(frame, 0x80, len); // Gray
 
   mozilla::layers::PlanarYCbCrData data;
   data.mYChannel = frame;
   data.mYSize = mozilla::gfx::IntSize(WIDTH, HEIGHT);
   data.mYStride = WIDTH * lumaBpp / 8.0;
   data.mCbCrStride = WIDTH * chromaBpp / 8.0;
   data.mCbChannel = frame + HEIGHT * data.mYStride;
@@ -208,21 +208,21 @@ Fake_VideoStreamSource::Notify(nsITimer*
 
 #if 0
 // Fake up buffer recycle bin
 mozilla::layers::BufferRecycleBin::BufferRecycleBin() :
  mLock("mozilla.layers.BufferRecycleBin.mLock") {
 }
 
 void mozilla::layers::BufferRecycleBin::RecycleBuffer(uint8_t* buffer, uint32_t size) {
-  PR_Free(buffer);
+  free(buffer);
 }
 
 uint8_t *mozilla::layers::BufferRecycleBin::GetBuffer(uint32_t size) {
-  return (uint8_t *)PR_MALLOC(size);
+  return (uint8_t*) malloc(size);
 }
 
 // YCbCrImage constructor (from ImageLayers.cpp)
 mozilla::layers::PlanarYCbCrImage::PlanarYCbCrImage(BufferRecycleBin *aRecycleBin)
   : Image(nsnull, ImageFormat::PLANAR_YCBCR)
   , mBufferSize(0)
   , mRecycleBin(aRecycleBin)
 {
--- a/mozglue/android/NSSBridge.h
+++ b/mozglue/android/NSSBridge.h
@@ -9,17 +9,16 @@
 #include "pk11func.h"
 #include "pk11sdr.h"
 #include "seccomon.h"
 #include "secitem.h"
 #include "secmodt.h"
 
 #include "prerror.h"
 #include "plstr.h"
-#include "prmem.h"
 
 #include <jni.h>
 
 int setup_nss_functions(void *nss_handle, void *nssutil_handle, void *plc_handle);
 
 #define NSS_WRAPPER(name, return_type, args...) \
 typedef return_type (*name ## _t)(args);  \
 extern name ## _t f_ ## name;
--- a/netwerk/base/NetworkActivityMonitor.cpp
+++ b/netwerk/base/NetworkActivityMonitor.cpp
@@ -264,17 +264,17 @@ NetworkActivityMonitor::AttachIOLayer(PR
                                sNetActivityMonitorLayerMethodsPtr);
   if (!layer) {
     return NS_ERROR_FAILURE;
   }
 
   status = PR_PushIOLayer(fd, PR_NSPR_IO_LAYER, layer);
 
   if (status == PR_FAILURE) {
-    PR_DELETE(layer);
+    PR_Free(layer); // PR_CreateIOLayerStub() uses PR_Malloc().
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 nsresult
 NetworkActivityMonitor::DataInOut(Direction direction)
--- a/netwerk/base/ShutdownLayer.cpp
+++ b/netwerk/base/ShutdownLayer.cpp
@@ -68,13 +68,13 @@ nsresult mozilla::net::AttachShutdownLay
                                sWinSockShutdownLayerMethodsPtr);
   if (!layer) {
     return NS_OK;
   }
 
   status = PR_PushIOLayer(aFd, PR_NSPR_IO_LAYER, layer);
 
   if (status == PR_FAILURE) {
-    PR_DELETE(layer);
+    PR_Free(layer); // PR_CreateIOLayerStub() uses PR_Malloc().
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
--- a/netwerk/base/TCPFastOpenLayer.cpp
+++ b/netwerk/base/TCPFastOpenLayer.cpp
@@ -346,17 +346,17 @@ AttachTCPFastOpenIOLayer(PRFileDesc *fd)
   TCPFastOpenSecret *secret = new TCPFastOpenSecret();
 
   layer->secret = reinterpret_cast<PRFilePrivate *>(secret);
 
   PRStatus status = PR_PushIOLayer(fd, PR_NSPR_IO_LAYER, layer);
 
   if (status == PR_FAILURE) {
     delete secret;
-    PR_DELETE(layer);
+    PR_Free(layer); // PR_CreateIOLayerStub() uses PR_Malloc().
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
 void
 TCPFastOpenFinish(PRFileDesc *fd, PRErrorCode &err,
                   bool &fastOpenNotSupported, uint8_t &tfoStatus)
--- a/netwerk/base/nsBase64Encoder.cpp
+++ b/netwerk/base/nsBase64Encoder.cpp
@@ -55,13 +55,13 @@ nsBase64Encoder::IsNonBlocking(bool* aNo
 nsresult
 nsBase64Encoder::Finish(nsACString& result)
 {
   char* b64 = PL_Base64Encode(mData.get(), mData.Length(), nullptr);
   if (!b64)
     return NS_ERROR_OUT_OF_MEMORY;
 
   result.Assign(b64);
-  PR_Free(b64);
+  PR_Free(b64); // PL_Base64Encode() uses PR_MALLOC().
   // Free unneeded memory and allow reusing the object
   mData.Truncate();
   return NS_OK;
 }
--- a/netwerk/cache/nsDiskCacheMap.cpp
+++ b/netwerk/cache/nsDiskCacheMap.cpp
@@ -83,18 +83,18 @@ nsDiskCacheMap::Open(nsIFile *  cacheDir
             *corruptInfo = nsDiskCache::kCreateCacheSubdirectories;
             goto error_exit;
         }
 
         // create the file - initialize in memory
         memset(&mHeader, 0, sizeof(nsDiskCacheHeader));
         mHeader.mVersion = nsDiskCache::kCurrentVersion;
         mHeader.mRecordCount = kMinRecordCount;
-        mRecordArray = (nsDiskCacheRecord *)
-            PR_CALLOC(mHeader.mRecordCount * sizeof(nsDiskCacheRecord));
+        mRecordArray = (nsDiskCacheRecord*)
+            calloc(mHeader.mRecordCount, sizeof(nsDiskCacheRecord));
         if (!mRecordArray) {
             *corruptInfo = nsDiskCache::kOutOfMemory;
             rv = NS_ERROR_OUT_OF_MEMORY;
             goto error_exit;
         }
     } else if (mapSize >= sizeof(nsDiskCacheHeader)) {  // read existing _CACHE_MAP_
         
         // if _CACHE_MAP_ exists, so should the block files
@@ -126,17 +126,17 @@ nsDiskCacheMap::Open(nsIFile *  cacheDir
         uint32_t recordArraySize =
                 mHeader.mRecordCount * sizeof(nsDiskCacheRecord);
         if (mapSize < recordArraySize + sizeof(nsDiskCacheHeader)) {
             *corruptInfo = nsDiskCache::kRecordsIncomplete;
             goto error_exit;
         }
 
         // Get the space for the records
-        mRecordArray = (nsDiskCacheRecord *) PR_MALLOC(recordArraySize);
+        mRecordArray = (nsDiskCacheRecord*) malloc(recordArraySize);
         if (!mRecordArray) {
             *corruptInfo = nsDiskCache::kOutOfMemory;
             rv = NS_ERROR_OUT_OF_MEMORY;
             goto error_exit;
         }
 
         // Read the records
         bytesRead = PR_Read(mMapFD, mRecordArray, recordArraySize);
@@ -225,18 +225,20 @@ nsDiskCacheMap::Close(bool flush)
         mMapFD = nullptr;
     }
 
     if (mCleanFD) {
         PR_Close(mCleanFD);
         mCleanFD = nullptr;
     }
 
-    PR_FREEIF(mRecordArray);
-    PR_FREEIF(mBuffer);
+    free(mRecordArray);
+    mRecordArray = nullptr;
+    free(mBuffer);
+    mBuffer = nullptr;
     mBufferSize = 0;
     return rv;
 }
 
 
 nsresult
 nsDiskCacheMap::Trim()
 {
@@ -343,18 +345,18 @@ nsDiskCacheMap::GrowRecords()
     if (mHeader.mRecordCount >= mMaxRecordCount)
         return NS_OK;
     CACHE_LOG_DEBUG(("CACHE: GrowRecords\n"));
 
     // Resize the record array
     int32_t newCount = mHeader.mRecordCount << 1;
     if (newCount > mMaxRecordCount)
         newCount = mMaxRecordCount;
-    nsDiskCacheRecord *newArray = (nsDiskCacheRecord *)
-            PR_REALLOC(mRecordArray, newCount * sizeof(nsDiskCacheRecord));
+    nsDiskCacheRecord* newArray = (nsDiskCacheRecord *)
+            realloc(mRecordArray, newCount * sizeof(nsDiskCacheRecord));
     if (!newArray)
         return NS_ERROR_OUT_OF_MEMORY;
 
     // Space out the buckets
     uint32_t oldRecordsPerBucket = GetRecordsPerBucket();
     uint32_t newRecordsPerBucket = newCount / kBuckets;
     // Work from back to space out each bucket to the new array
     for (int bucketIndex = kBuckets - 1; bucketIndex >= 0; --bucketIndex) {
@@ -409,17 +411,17 @@ nsDiskCacheMap::ShrinkRecords()
         memmove(mRecordArray + bucketIndex * newRecordsPerBucket,
                 mRecordArray + bucketIndex * oldRecordsPerBucket,
                 newRecordsPerBucket * sizeof(nsDiskCacheRecord));
     }
 
     // Shrink the record array memory block itself
     uint32_t newCount = newRecordsPerBucket * kBuckets;
     nsDiskCacheRecord* newArray = (nsDiskCacheRecord *)
-            PR_REALLOC(mRecordArray, newCount * sizeof(nsDiskCacheRecord));
+            realloc(mRecordArray, newCount * sizeof(nsDiskCacheRecord));
     if (!newArray)
         return NS_ERROR_OUT_OF_MEMORY;
 
     // Set as the new record array
     mRecordArray = newArray;
     mHeader.mRecordCount = newCount;
 
     InvalidateCache();
@@ -1186,17 +1188,17 @@ nsDiskCacheMap::CalculateFileIndex(uint3
     if (size <= 4 * BLOCK_SIZE_FOR_INDEX(3))  return 3;
     return 0;
 }
 
 nsresult
 nsDiskCacheMap::EnsureBuffer(uint32_t bufSize)
 {
     if (mBufferSize < bufSize) {
-        char * buf = (char *)PR_REALLOC(mBuffer, bufSize);
+        char* buf = (char*) realloc(mBuffer, bufSize);
         if (!buf) {
             mBufferSize = 0;
             return NS_ERROR_OUT_OF_MEMORY;
         }
         mBuffer = buf;
         mBufferSize = bufSize;
     }
     return NS_OK;
--- a/netwerk/mime/nsMIMEHeaderParamImpl.cpp
+++ b/netwerk/mime/nsMIMEHeaderParamImpl.cpp
@@ -1,16 +1,15 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=4 ts=8 et tw=80 : */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <string.h>
-#include "prmem.h"
 #include "prprf.h"
 #include "plstr.h"
 #include "plbase64.h"
 #include "nsCRT.h"
 #include "nsMemory.h"
 #include "nsTArray.h"
 #include "nsCOMPtr.h"
 #include "nsEscape.h"
@@ -967,17 +966,17 @@ nsMIMEHeaderParamImpl::DecodeParameter(c
          (0x61 <= uint8_t(c) && uint8_t(c) <= 0x66))
 
 // Decode Q encoding (RFC 2047).
 // static
 char *DecodeQ(const char *in, uint32_t length)
 {
   char *out, *dest = nullptr;
 
-  out = dest = (char *)PR_Calloc(length + 1, sizeof(char));
+  out = dest = (char*) calloc(length + 1, sizeof(char));
   if (dest == nullptr)
     return nullptr;
   while (length > 0) {
     unsigned c = 0;
     switch (*in) {
     case '=':
       // check if |in| in the form of '=hh'  where h is [0-9a-fA-F].
       if (length < 3 || !ISHEXCHAR(in[1]) || !ISHEXCHAR(in[2]))
@@ -1005,17 +1004,17 @@ char *DecodeQ(const char *in, uint32_t l
   for (out = dest; *out ; ++out) {
     if (*out == '\t')
       *out = ' ';
   }
 
   return dest;
 
  badsyntax:
-  PR_Free(dest);
+  free(dest);
   return nullptr;
 }
 
 // check if input is HZ (a 7bit encoding for simplified Chinese : RFC 1842)) 
 // or has  ESC which may be an  indication that  it's in one of many ISO 
 // 2022 7bit  encodings (e.g. ISO-2022-JP(-2)/CN : see RFC 1468, 1922, 1554).
 // static
 bool Is7bitNonAsciiString(const char *input, uint32_t len)
@@ -1141,17 +1140,17 @@ nsresult DecodeQOrBase64Str(const char *
   nsAutoCString utf8Text;
   if (NS_SUCCEEDED(rv)) {
     // skip ASCIIness/UTF8ness test if aCharset is 7bit non-ascii charset.
     rv = cvtUTF8->ConvertStringToUTF8(nsDependentCString(decodedText),
                                       aCharset,
                                       IS_7BIT_NON_ASCII_CHARSET(aCharset),
                                       true, 1, utf8Text);
   }
-  PR_Free(decodedText);
+  free(decodedText);
   if (NS_FAILED(rv)) {
     return rv;
   }
   aResult.Append(utf8Text);
 
   return NS_OK;
 }
 
--- a/netwerk/protocol/websocket/WebSocketChannel.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannel.cpp
@@ -2864,17 +2864,17 @@ WebSocketChannel::SetupRequest()
 
   rv = mRandomGenerator->GenerateRandomBytes(16, &secKey);
   NS_ENSURE_SUCCESS(rv, rv);
   char* b64 = PL_Base64Encode((const char *)secKey, 16, nullptr);
   free(secKey);
   if (!b64)
     return NS_ERROR_OUT_OF_MEMORY;
   secKeyString.Assign(b64);
-  PR_Free(b64);
+  PR_Free(b64); // PL_Base64Encode() uses PR_Malloc.
   rv = mHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Sec-WebSocket-Key"),
                                       secKeyString, false);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
   LOG(("WebSocketChannel::SetupRequest: client key %s\n", secKeyString.get()));
 
   // prepare the value we expect to see in
   // the sec-websocket-accept response header
   rv = CalculateWebSocketHashedSecret(secKeyString, mHashedSecret);
--- a/netwerk/socket/nsNamedPipeIOLayer.cpp
+++ b/netwerk/socket/nsNamedPipeIOLayer.cpp
@@ -706,17 +706,17 @@ nsNamedPipeClose(PRFileDesc* aFd)
   if (aFd->secret && PR_GetLayersIdentity(aFd) == nsNamedPipeLayerIdentity) {
     RefPtr<NamedPipeInfo> info = dont_AddRef(GetNamedPipeInfo(aFd));
     info->Disconnect();
     aFd->secret = nullptr;
     aFd->identity = PR_INVALID_IO_LAYER;
   }
 
   MOZ_ASSERT(!aFd->lower);
-  PR_DELETE(aFd);
+  PR_Free(aFd); // PRFileDescs are allocated with PR_Malloc().
 
   return PR_SUCCESS;
 }
 
 static PRInt32
 nsNamedPipeSend(PRFileDesc* aFd,
                 const void* aBuffer,
                 PRInt32 aAmount,
--- a/netwerk/socket/nsSOCKSIOLayer.cpp
+++ b/netwerk/socket/nsSOCKSIOLayer.cpp
@@ -1567,17 +1567,17 @@ nsSOCKSIOLayerAddToSocket(int32_t family
         return NS_ERROR_FAILURE;
     }
 
     nsSOCKSSocketInfo * infoObject = new nsSOCKSSocketInfo();
     if (!infoObject)
     {
         // clean up IOLayerStub
         LOGERROR(("Failed to create nsSOCKSSocketInfo()."));
-        PR_DELETE(layer);
+        PR_Free(layer); // PR_CreateIOLayerStub() uses PR_Malloc().
         return NS_ERROR_FAILURE;
     }
 
     NS_ADDREF(infoObject);
     infoObject->Init(socksVersion, family, proxy, host, flags);
     layer->secret = (PRFilePrivate*) infoObject;
 
     PRDescIdentity fdIdentity = PR_GetLayersIdentity(fd);
@@ -1588,17 +1588,17 @@ nsSOCKSIOLayerAddToSocket(int32_t family
         infoObject->SetNamedPipeFD(fd);
     }
 #endif
     rv = PR_PushIOLayer(fd, fdIdentity, layer);
 
     if (rv == PR_FAILURE) {
         LOGERROR(("PR_PushIOLayer() failed. rv = %x.", rv));
         NS_RELEASE(infoObject);
-        PR_DELETE(layer);
+        PR_Free(layer); // PR_CreateIOLayerStub() uses PR_Malloc().
         return NS_ERROR_FAILURE;
     }
 
     *info = static_cast<nsISOCKSSocketInfo*>(infoObject);
     NS_ADDREF(*info);
     return NS_OK;
 }
 
--- a/parser/htmlparser/nsExpatDriver.cpp
+++ b/parser/htmlparser/nsExpatDriver.cpp
@@ -10,17 +10,16 @@
 #include "nsIExpatSink.h"
 #include "nsIExtendedExpatSink.h"
 #include "nsIContentSink.h"
 #include "nsParserMsgUtils.h"
 #include "nsIURL.h"
 #include "nsIUnicharInputStream.h"
 #include "nsIProtocolHandler.h"
 #include "nsNetUtil.h"
-#include "prmem.h"
 #include "nsTextFormatter.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsCRT.h"
 #include "nsIConsoleService.h"
 #include "nsIScriptError.h"
 #include "nsIContentPolicy.h"
 #include "nsContentPolicyUtils.h"
 #include "nsError.h"
@@ -1223,22 +1222,21 @@ nsExpatDriver::WillBuildModel(const CPar
     NS_ERROR("nsExpatDriver didn't get an nsIExpatSink");
     // Make sure future calls to us bail out as needed
     mInternalState = NS_ERROR_UNEXPECTED;
     return mInternalState;
   }
 
   mOriginalSink = aSink;
 
-  static const XML_Memory_Handling_Suite memsuite =
-    {
-      (void *(*)(size_t))PR_Malloc,
-      (void *(*)(void *, size_t))PR_Realloc,
-      PR_Free
-    };
+  static const XML_Memory_Handling_Suite memsuite = {
+    malloc,
+    realloc,
+    free
+  };
 
   static const char16_t kExpatSeparator[] = { kExpatSeparatorChar, '\0' };
 
   mExpatParser = XML_ParserCreate_MM(kUTF16, &memsuite, kExpatSeparator);
   NS_ENSURE_TRUE(mExpatParser, NS_ERROR_FAILURE);
 
   XML_SetReturnNSTriplet(mExpatParser, XML_TRUE);
 
--- a/rdf/base/nsRDFContentSink.cpp
+++ b/rdf/base/nsRDFContentSink.cpp
@@ -742,17 +742,17 @@ RDFContentSinkImpl::AddText(const char16
     }
 
     // Copy data from string into our buffer; grow the buffer as needed.
     // It never shrinks, but since the content sink doesn't stick around,
     // this shouldn't be a bloat issue.
     int32_t amount = mTextSize - mTextLength;
     if (amount < aLength) {
         // Grow the buffer by at least a factor of two to prevent thrashing.
-        // Since PR_REALLOC will leave mText intact if the call fails,
+        // Since realloc() will leave mText intact if the call fails,
         // don't clobber mText or mTextSize until the new mem is allocated.
         int32_t newSize = (2 * mTextSize > (mTextSize + aLength)) ?
                           (2 * mTextSize) : (mTextSize + aLength);
         char16_t* newText = 
             (char16_t *) realloc(mText, sizeof(char16_t) * newSize);
         if (!newText)
             return NS_ERROR_OUT_OF_MEMORY;
         mTextSize = newSize;
--- a/rdf/base/nsRDFService.cpp
+++ b/rdf/base/nsRDFService.cpp
@@ -47,17 +47,16 @@
 #include "nsXPIDLString.h"
 #include "nsNetUtil.h"
 #include "nsIURI.h"
 #include "PLDHashTable.h"
 #include "plhash.h"
 #include "plstr.h"
 #include "mozilla/Logging.h"
 #include "prprf.h"
-#include "prmem.h"
 #include "rdf.h"
 #include "nsCRT.h"
 #include "nsCRTGlue.h"
 #include "mozilla/HashFunctions.h"
 #include "mozilla/IntegerPrintfMacros.h"
 
 using namespace mozilla;
 
@@ -78,37 +77,37 @@ class BlobImpl;
 
 // These functions are copied from nsprpub/lib/ds/plhash.c, with one
 // change to free the key in DataSourceFreeEntry.
 // XXX sigh, why were DefaultAllocTable et. al. declared static, anyway?
 
 static void *
 DataSourceAllocTable(void *pool, size_t size)
 {
-    return PR_MALLOC(size);
+    return malloc(size);
 }
 
 static void
 DataSourceFreeTable(void *pool, void *item)
 {
-    PR_Free(item);
+    free(item);
 }
 
 static PLHashEntry *
 DataSourceAllocEntry(void *pool, const void *key)
 {
-    return PR_NEW(PLHashEntry);
+    return (PLHashEntry*) malloc(sizeof(PLHashEntry));
 }
 
 static void
 DataSourceFreeEntry(void *pool, PLHashEntry *he, unsigned flag)
 {
     if (flag == HT_FREE_ENTRY) {
         PL_strfree((char*) he->key);
-        PR_Free(he);
+        free(he);
     }
 }
 
 static PLHashAllocOps dataSourceHashAllocOps = {
     DataSourceAllocTable, DataSourceFreeTable,
     DataSourceAllocEntry, DataSourceFreeEntry
 };
 
--- a/security/certverifier/NSSCertDBTrustDomain.cpp
+++ b/security/certverifier/NSSCertDBTrustDomain.cpp
@@ -24,17 +24,16 @@
 #include "nsNSSCertificate.h"
 #include "nsServiceManagerUtils.h"
 #include "nss.h"
 #include "pk11pub.h"
 #include "pkix/Result.h"
 #include "pkix/pkix.h"
 #include "pkix/pkixnss.h"
 #include "prerror.h"
-#include "prmem.h"
 #include "secerr.h"
 
 #include "CNNICHashWhitelist.inc"
 #include "StartComAndWoSignData.inc"
 
 using namespace mozilla;
 using namespace mozilla::pkix;
 
--- a/security/manager/ssl/nsNSSCertificate.cpp
+++ b/security/manager/ssl/nsNSSCertificate.cpp
@@ -34,17 +34,16 @@
 #include "nsString.h"
 #include "nsThreadUtils.h"
 #include "nsUnicharUtils.h"
 #include "nspr.h"
 #include "pkix/pkixnss.h"
 #include "pkix/pkixtypes.h"
 #include "pkix/Result.h"
 #include "prerror.h"
-#include "prmem.h"
 #include "secasn1.h"
 #include "secder.h"
 #include "secerr.h"
 #include "ssl.h"
 
 #ifdef XP_WIN
 #include <winsock.h> // for htonl
 #endif
--- a/security/manager/ssl/nsNSSComponent.cpp
+++ b/security/manager/ssl/nsNSSComponent.cpp
@@ -50,16 +50,17 @@
 #include "nss.h"
 #include "p12plcy.h"
 #include "pkix/pkixnss.h"
 #include "secerr.h"
 #include "secmod.h"
 #include "ssl.h"
 #include "sslerr.h"
 #include "sslproto.h"
+#include "prmem.h"
 
 #ifndef MOZ_NO_SMART_CARDS
 #include "nsSmartCardMonitor.h"
 #endif
 
 #ifdef XP_WIN
 #include "mozilla/WindowsVersion.h"
 #include "nsILocalFileWin.h"
@@ -1096,17 +1097,17 @@ nsNSSComponent::LoadLoadableRoots()
         if (!nss_path) {
           continue;
         }
         // Get the directory containing the nss3 library.
         nsCOMPtr<nsIFile> nssLib(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
         if (NS_SUCCEEDED(rv)) {
           rv = nssLib->InitWithNativePath(nsDependentCString(nss_path));
         }
-        PR_Free(nss_path);
+        PR_Free(nss_path); // PR_GetLibraryFilePathname() uses PR_Malloc().
         if (NS_SUCCEEDED(rv)) {
           nsCOMPtr<nsIFile> file;
           if (NS_SUCCEEDED(nssLib->GetParent(getter_AddRefs(file)))) {
             mozFile = do_QueryInterface(file);
           }
         }
       } else {
         directoryService->Get( possible_ckbi_locations[il],
--- a/security/manager/ssl/nsNSSIOLayer.cpp
+++ b/security/manager/ssl/nsNSSIOLayer.cpp
@@ -1869,35 +1869,35 @@ nsConvertCANamesToStrings(const UniquePL
             goto loser;
         }
 
         if (headerlen + contentlen != dername->len) {
             // This must be from an enterprise 2.x server, which sent
             // incorrectly formatted der without the outer wrapper of type and
             // length. Fix it up by adding the top level header.
             if (dername->len <= 127) {
-                newitem.data = (unsigned char*) PR_Malloc(dername->len + 2);
+                newitem.data = (unsigned char*) malloc(dername->len + 2);
                 if (!newitem.data) {
                     goto loser;
                 }
                 newitem.data[0] = (unsigned char) 0x30;
                 newitem.data[1] = (unsigned char) dername->len;
                 (void) memcpy(&newitem.data[2], dername->data, dername->len);
             } else if (dername->len <= 255) {
-                newitem.data = (unsigned char*) PR_Malloc(dername->len + 3);
+                newitem.data = (unsigned char*) malloc(dername->len + 3);
                 if (!newitem.data) {
                     goto loser;
                 }
                 newitem.data[0] = (unsigned char) 0x30;
                 newitem.data[1] = (unsigned char) 0x81;
                 newitem.data[2] = (unsigned char) dername->len;
                 (void) memcpy(&newitem.data[3], dername->data, dername->len);
             } else {
                 // greater than 256, better be less than 64k
-                newitem.data = (unsigned char*) PR_Malloc(dername->len + 4);
+                newitem.data = (unsigned char*) malloc(dername->len + 4);
                 if (!newitem.data) {
                     goto loser;
                 }
                 newitem.data[0] = (unsigned char) 0x30;
                 newitem.data[1] = (unsigned char) 0x82;
                 newitem.data[2] = (unsigned char) ((dername->len >> 8) & 0xff);
                 newitem.data[3] = (unsigned char) (dername->len & 0xff);
                 memcpy(&newitem.data[4], dername->data, dername->len);
@@ -1906,31 +1906,31 @@ nsConvertCANamesToStrings(const UniquePL
         }
 
         namestring = CERT_DerNameToAscii(dername);
         if (!namestring) {
             // XXX - keep going until we fail to convert the name
             caNameStrings[n] = const_cast<char*>("");
         } else {
             caNameStrings[n] = PORT_ArenaStrdup(arena.get(), namestring);
-            PR_Free(namestring);
+            PR_Free(namestring); // CERT_DerNameToAscii() uses PR_Malloc().
             if (!caNameStrings[n]) {
                 goto loser;
             }
         }
 
         if (newitem.data) {
-            PR_Free(newitem.data);
+            free(newitem.data);
         }
     }
 
     return SECSuccess;
 loser:
     if (newitem.data) {
-        PR_Free(newitem.data);
+        free(newitem.data);
     }
     return SECFailure;
 }
 
 // Possible behaviors for choosing a cert for client auth.
 enum class UserCertChoice {
   // Ask the user to choose a cert.
   Ask = 0,
--- a/security/manager/ssl/nsPKCS12Blob.cpp
+++ b/security/manager/ssl/nsPKCS12Blob.cpp
@@ -13,17 +13,16 @@
 #include "nsIInputStream.h"
 #include "nsNSSCertHelper.h"
 #include "nsNSSCertificate.h"
 #include "nsNSSHelper.h"
 #include "nsNetUtil.h"
 #include "nsReadableUtils.h"
 #include "nsThreadUtils.h"
 #include "pkix/pkixtypes.h"
-#include "prmem.h"
 #include "secerr.h"
 
 using namespace mozilla;
 extern LazyLogModule gPIPNSSLog;
 
 #define PIP_PKCS12_TMPFILENAME   NS_LITERAL_CSTRING(".pip_p12tmp")
 #define PIP_PKCS12_BUFFER_SIZE   2048
 #define PIP_PKCS12_USER_CANCELED       3
--- a/security/manager/ssl/nsSmartCardMonitor.cpp
+++ b/security/manager/ssl/nsSmartCardMonitor.cpp
@@ -237,18 +237,18 @@ void SmartCardMonitoringThread::Stop()
 //
 void
 SmartCardMonitoringThread::SetTokenName(CK_SLOT_ID slotid,
                                        const char* tokenName, uint32_t series)
 {
   if (mHash) {
     if (tokenName) {
       int len = strlen(tokenName) + 1;
-      /* this must match the allocator used in
-       * PLHashAllocOps.freeEntry DefaultFreeEntry */
+      // Use PR_Malloc() because PLHashAllocOps.freeEntry for mHash is
+      // DefaultFreeEntry(), which uses PR_Free().
       char* entry = (char*)PR_Malloc(len + sizeof(uint32_t));
 
       if (entry) {
         memcpy(entry, &series, sizeof(uint32_t));
         memcpy(&entry[sizeof(uint32_t)], tokenName, len);
 
         PL_HashTableAdd(mHash, (void*)(uintptr_t)slotid, entry); /* adopt */
         return;
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -79,17 +79,16 @@
 #include "InjectCrashReporter.h"
 using mozilla::InjectCrashRunnable;
 #endif
 
 #include <stdlib.h>
 #include <time.h>
 #include <prenv.h>
 #include <prio.h>
-#include <prmem.h>
 #include "mozilla/Mutex.h"
 #include "nsDebug.h"
 #include "nsCRT.h"
 #include "nsIFile.h"
 #include <map>
 #include <vector>
 
 #include "mozilla/double-conversion.h"
--- a/toolkit/system/unixproxy/nsLibProxySettings.cpp
+++ b/toolkit/system/unixproxy/nsLibProxySettings.cpp
@@ -105,17 +105,17 @@ nsUnixSystemProxySettings::GetProxyForUR
     else {
       aResult.AppendLiteral("PROXY ");
       aResult.Append(proxyArray[c]);
     }
 
     c++;
   }
 
-  PR_Free(proxyArray);
+  free(proxyArray);
   return NS_OK;
 }
 
 #define NS_UNIXSYSTEMPROXYSERVICE_CID  /* 0fa3158c-d5a7-43de-9181-a285e74cf1d4 */\
      { 0x0fa3158c, 0xd5a7, 0x43de, \
        {0x91, 0x81, 0xa2, 0x85, 0xe7, 0x4c, 0xf1, 0xd4 } }
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsUnixSystemProxySettings, Init)
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -38,17 +38,16 @@
 #include "MacLaunchHelper.h"
 #include "MacApplicationDelegate.h"
 #include "MacAutoreleasePool.h"
 // these are needed for sysctl
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #endif
 
-#include "prmem.h"
 #include "prnetdb.h"
 #include "prprf.h"
 #include "prproces.h"
 #include "prenv.h"
 #include "prtime.h"
 
 #include "nsIAppShellService.h"
 #include "nsIAppStartup.h"
--- a/uriloader/exthandler/mac/nsDecodeAppleFile.cpp
+++ b/uriloader/exthandler/mac/nsDecodeAppleFile.cpp
@@ -1,47 +1,46 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  
 #include "nsDecodeAppleFile.h"
-#include "prmem.h"
 #include "nsCRT.h"
 
 
 NS_IMPL_ADDREF(nsDecodeAppleFile)
 NS_IMPL_RELEASE(nsDecodeAppleFile)
 
 NS_INTERFACE_MAP_BEGIN(nsDecodeAppleFile)
    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIOutputStream)
    NS_INTERFACE_MAP_ENTRY(nsIOutputStream)
 NS_INTERFACE_MAP_END_THREADSAFE
 
 nsDecodeAppleFile::nsDecodeAppleFile()
 {
   m_state = parseHeaders;
   m_dataBufferLength = 0;
-  m_dataBuffer = (unsigned char*) PR_MALLOC(MAX_BUFFERSIZE);
+  m_dataBuffer = (unsigned char*) malloc(MAX_BUFFERSIZE);
   m_entries = nullptr;
   m_rfRefNum = -1;
   m_totalDataForkWritten = 0;
   m_totalResourceForkWritten = 0;
   m_headerOk = false;
   
   m_comment[0] = 0;
   memset(&m_dates, 0, sizeof(m_dates));
   memset(&m_finderInfo, 0, sizeof(m_dates));
   memset(&m_finderExtraInfo, 0, sizeof(m_dates));
 }
 
 nsDecodeAppleFile::~nsDecodeAppleFile()
 {
-  
-  PR_FREEIF(m_dataBuffer);
+  free(m_dataBuffer);
+  m_dataBuffer = nullptr;
   if (m_entries)
     delete [] m_entries;
 }
 
 NS_IMETHODIMP nsDecodeAppleFile::Initialize(nsIOutputStream *output, nsIFile *file)
 {
   m_output = output;
   
--- a/widget/windows/nsBidiKeyboard.cpp
+++ b/widget/windows/nsBidiKeyboard.cpp
@@ -2,17 +2,16 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <stdio.h>
 #include "nsBidiKeyboard.h"
 #include "WidgetUtils.h"
-#include "prmem.h"
 #include <tchar.h>
 
 NS_IMPL_ISUPPORTS(nsBidiKeyboard, nsIBidiKeyboard)
 
 nsBidiKeyboard::nsBidiKeyboard() : nsIBidiKeyboard()
 {
   Reset();
 }
@@ -97,23 +96,23 @@ nsresult nsBidiKeyboard::SetupBidiKeyboa
   bool isRTLKeyboardSet = false;
   
   // GetKeyboardLayoutList with 0 as first parameter returns the number of keyboard layouts available
   keyboards = ::GetKeyboardLayoutList(0, nullptr);
   if (!keyboards)
     return NS_ERROR_FAILURE;
 
   // allocate a buffer to hold the list
-  buf = (HKL far*) PR_Malloc(keyboards * sizeof(HKL));
+  buf = (HKL far*) malloc(keyboards * sizeof(HKL));
   if (!buf)
     return NS_ERROR_OUT_OF_MEMORY;
 
   // Call again to fill the buffer
   if (::GetKeyboardLayoutList(keyboards, buf) != keyboards) {
-    PR_Free(buf);
+    free(buf);
     return NS_ERROR_UNEXPECTED;
   }
 
   // Go through the list and pick a default LTR and RTL keyboard layout
   while (keyboards--) {
     locale = buf[keyboards];
     if (IsRTLLanguage(locale)) {
       _snwprintf(mRTLKeyboard, KL_NAMELENGTH, L"%.*x", KL_NAMELENGTH - 1,
@@ -121,17 +120,17 @@ nsresult nsBidiKeyboard::SetupBidiKeyboa
       isRTLKeyboardSet = true;
     }
     else {
       _snwprintf(mLTRKeyboard, KL_NAMELENGTH, L"%.*x", KL_NAMELENGTH - 1,
                  LANGIDFROMLCID((DWORD_PTR)locale));
       isLTRKeyboardSet = true;
     }
   }
-  PR_Free(buf);
+  free(buf);
   mInitialized = true;
 
   // If there is not at least one keyboard of each directionality, Bidi
   // keyboard functionality will be disabled.
   mHaveBidiKeyboards = (isRTLKeyboardSet && isLTRKeyboardSet);
   if (!mHaveBidiKeyboards)
     return NS_ERROR_FAILURE;
 
--- a/widget/windows/nsDeviceContextSpecWin.cpp
+++ b/widget/windows/nsDeviceContextSpecWin.cpp
@@ -7,18 +7,16 @@
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/gfx/PrintTargetPDF.h"
 #include "mozilla/gfx/PrintTargetWindows.h"
 #include "mozilla/Logging.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/RefPtr.h"
 
-#include "prmem.h"
-
 #include <winspool.h>
 
 #include "nsIWidget.h"
 
 #include "nsTArray.h"
 #include "nsIPrintSettingsWin.h"
 
 #include "nsString.h"
@@ -220,23 +218,23 @@ NS_IMETHODIMP nsDeviceContextSpecWin::In
 // Helper Function - Free and reallocate the string
 static void CleanAndCopyString(wchar_t*& aStr, const wchar_t* aNewStr)
 {
   if (aStr != nullptr) {
     if (aNewStr != nullptr && wcslen(aStr) > wcslen(aNewStr)) { // reuse it if we can
       wcscpy(aStr, aNewStr);
       return;
     } else {
-      PR_Free(aStr);
+      free(aStr);
       aStr = nullptr;
     }
   }
 
   if (nullptr != aNewStr) {
-    aStr = (wchar_t *)PR_Malloc(sizeof(wchar_t)*(wcslen(aNewStr) + 1));
+    aStr = (wchar_t*) malloc(sizeof(wchar_t) * (wcslen(aNewStr) + 1));
     wcscpy(aStr, aNewStr);
   }
 }
 
 already_AddRefed<PrintTarget> nsDeviceContextSpecWin::MakePrintTarget()
 {
   NS_ASSERTION(mDevMode, "DevMode can't be NULL here");
 
--- a/widget/windows/nsImageClipboard.cpp
+++ b/widget/windows/nsImageClipboard.cpp
@@ -7,17 +7,16 @@
 
 #include "gfxUtils.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/DataSurfaceHelpers.h"
 #include "mozilla/RefPtr.h"
 #include "nsITransferable.h"
 #include "nsGfxCIID.h"
 #include "nsMemory.h"
-#include "prmem.h"
 #include "imgIEncoder.h"
 #include "nsLiteralString.h"
 #include "nsComponentManagerUtils.h"
 
 #define BFH_LENGTH 14
 
 using namespace mozilla;
 using namespace mozilla::gfx;
--- a/widget/windows/nsSound.cpp
+++ b/widget/windows/nsSound.cpp
@@ -18,17 +18,16 @@
 #include "nsNetUtil.h"
 #include "nsIChannel.h"
 #include "nsContentUtils.h"
 #include "nsCRT.h"
 #include "nsIObserverService.h"
 
 #include "mozilla/Logging.h"
 #include "prtime.h"
-#include "prmem.h"
 
 #include "nsNativeCharsetUtils.h"
 #include "nsThreadUtils.h"
 #include "mozilla/ClearOnShutdown.h"
 
 using mozilla::LogLevel;
 
 static mozilla::LazyLogModule gWin32SoundLog("nsSound");
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -75,17 +75,16 @@
 #include <wtsapi32.h>
 #include <process.h>
 #include <commctrl.h>
 #include <unknwn.h>
 #include <psapi.h>
 
 #include "mozilla/Logging.h"
 #include "prtime.h"
-#include "prmem.h"
 #include "prenv.h"
 
 #include "mozilla/WidgetTraceEvent.h"
 #include "nsIAppShell.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIDOMMouseEvent.h"
 #include "nsIKeyEventInPluginCallback.h"
 #include "nsITheme.h"
--- a/widget/windows/nsWindowGfx.cpp
+++ b/widget/windows/nsWindowGfx.cpp
@@ -32,17 +32,16 @@ using mozilla::plugins::PluginInstancePa
 #include "gfxDWriteFonts.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/DataSurfaceHelpers.h"
 #include "mozilla/gfx/Tools.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/UniquePtrExtensions.h"
 #include "nsGfxCIID.h"
 #include "gfxContext.h"
-#include "prmem.h"
 #include "WinUtils.h"
 #include "nsIWidgetListener.h"
 #include "mozilla/Unused.h"
 #include "nsDebug.h"
 #include "nsIXULRuntime.h"
 
 #include "mozilla/gfx/GPUProcessManager.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
@@ -551,17 +550,17 @@ nsresult nsWindowGfx::CreateIcon(imgICon
   if (map.mData) {
     dataSurface->Unmap();
   }
   if (!a1data) {
     return NS_ERROR_FAILURE;
   }
 
   HBITMAP mbmp = DataToBitmap(a1data, iconSize.width, -iconSize.height, 1);
-  PR_Free(a1data);
+  free(a1data);
 
   ICONINFO info = {0};
   info.fIcon = !aIsCursor;
   info.xHotspot = aHotspotX;
   info.yHotspot = aHotspotY;
   info.hbmMask = mbmp;
   info.hbmColor = bmp;
 
@@ -578,17 +577,17 @@ nsresult nsWindowGfx::CreateIcon(imgICon
 uint8_t* nsWindowGfx::Data32BitTo1Bit(uint8_t* aImageData,
                                       uint32_t aWidth, uint32_t aHeight)
 {
   // We need (aWidth + 7) / 8 bytes plus zero-padding up to a multiple of
   // 4 bytes for each row (HBITMAP requirement). Bug 353553.
   uint32_t outBpr = ((aWidth + 31) / 8) & ~3;
 
   // Allocate and clear mask buffer
-  uint8_t* outData = (uint8_t*)PR_Calloc(outBpr, aHeight);
+  uint8_t* outData = (uint8_t*) calloc(outBpr, aHeight);
   if (!outData)
     return nullptr;
 
   int32_t *imageRow = (int32_t*)aImageData;
   for (uint32_t curRow = 0; curRow < aHeight; curRow++) {
     uint8_t *outRow = outData + curRow * outBpr;
     uint8_t mask = 0x80;
     for (uint32_t curCol = 0; curCol < aWidth; curCol++) {
--- a/widget/xremoteclient/XRemoteClient.cpp
+++ b/widget/xremoteclient/XRemoteClient.cpp
@@ -5,17 +5,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Sprintf.h"
 #include "XRemoteClient.h"
-#include "prmem.h"
 #include "plstr.h"
 #include "prsystem.h"
 #include "mozilla/Logging.h"
 #include "prenv.h"
 #include "prdtoa.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
--- a/xpcom/base/nsTraceRefcnt.cpp
+++ b/xpcom/base/nsTraceRefcnt.cpp
@@ -45,17 +45,16 @@
 #ifdef MOZ_DMD
 #include "base/process_util.h"
 #include "nsMemoryInfoDumper.h"
 #endif
 
 ////////////////////////////////////////////////////////////////////////////////
 
 #include "plhash.h"
-#include "prmem.h"
 
 #include "prthread.h"
 
 // We use a spin lock instead of a regular mutex because this lock is usually
 // only held for a very short time, and gets grabbed at a very high frequency
 // (~100000 times per second). On Mac, the overhead of using a regular lock
 // is very high, see bug 1137963.
 static mozilla::Atomic<uintptr_t, mozilla::ReleaseAcquire> gTraceLogLocked;
@@ -183,46 +182,46 @@ AssertActivityIsLegal()
 
 // These functions are copied from nsprpub/lib/ds/plhash.c, with changes
 // to the functions not called Default* to free the SerialNumberRecord or
 // the BloatEntry.
 
 static void*
 DefaultAllocTable(void* aPool, size_t aSize)
 {
-  return PR_MALLOC(aSize);
+  return malloc(aSize);
 }
 
 static void
 DefaultFreeTable(void* aPool, void* aItem)
 {
-  PR_Free(aItem);
+  free(aItem);
 }
 
 static PLHashEntry*
 DefaultAllocEntry(void* aPool, const void* aKey)
 {
-  return PR_NEW(PLHashEntry);
+  return (PLHashEntry*) malloc(sizeof(PLHashEntry));
 }
 
 static void
 SerialNumberFreeEntry(void* aPool, PLHashEntry* aHashEntry, unsigned aFlag)
 {
   if (aFlag == HT_FREE_ENTRY) {
     delete static_cast<SerialNumberRecord*>(aHashEntry->value);
-    PR_Free(aHashEntry);
+    free(aHashEntry);
   }
 }
 
 static void
 TypesToLogFreeEntry(void* aPool, PLHashEntry* aHashEntry, unsigned aFlag)
 {
   if (aFlag == HT_FREE_ENTRY) {
     free(const_cast<char*>(static_cast<const char*>(aHashEntry->key)));
-    PR_Free(aHashEntry);
+    free(aHashEntry);
   }
 }
 
 static const PLHashAllocOps serialNumberHashAllocOps = {
   DefaultAllocTable, DefaultFreeTable,
   DefaultAllocEntry, SerialNumberFreeEntry
 };
 
@@ -387,17 +386,17 @@ protected:
 };
 
 static void
 BloatViewFreeEntry(void* aPool, PLHashEntry* aHashEntry, unsigned aFlag)
 {
   if (aFlag == HT_FREE_ENTRY) {
     BloatEntry* entry = static_cast<BloatEntry*>(aHashEntry->value);
     delete entry;
-    PR_Free(aHashEntry);
+    free(aHashEntry);
   }
 }
 
 const static PLHashAllocOps bloatViewHashAllocOps = {
   DefaultAllocTable, DefaultFreeTable,
   DefaultAllocEntry, BloatViewFreeEntry
 };
 
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -1903,29 +1903,29 @@ nsLocalFile::SetPersistentDescriptor(con
     NS_ERROR("SetPersistentDescriptor was given bad data");
     return NS_ERROR_FAILURE;
   }
 
   // Cast to an alias record and resolve.
   AliasRecord aliasHeader = *(AliasPtr)decodedData;
   int32_t aliasSize = ::GetAliasSizeFromPtr(&aliasHeader);
   if (aliasSize > ((int32_t)dataSize * 3) / 4) { // be paranoid about having too few data
-    PR_Free(decodedData);
+    PR_Free(decodedData); // PL_Base64Decode() uses PR_Malloc().
     return NS_ERROR_FAILURE;
   }
 
   nsresult rv = NS_OK;
 
   // Move the now-decoded data into the Handle.
   // The size of the decoded data is 3/4 the size of the encoded data. See plbase64.h
   Handle  newHandle = nullptr;
   if (::PtrToHand(decodedData, &newHandle, aliasSize) != noErr) {
     rv = NS_ERROR_OUT_OF_MEMORY;
   }
-  PR_Free(decodedData);
+  PR_Free(decodedData); // PL_Base64Decode() uses PR_Malloc().
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   Boolean changed;
   FSRef resolvedFSRef;
   OSErr err = ::FSResolveAlias(nullptr, (AliasHandle)newHandle, &resolvedFSRef,
                                &changed);
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -16,17 +16,16 @@
 #include "nsLocalFile.h"
 #include "nsIDirectoryEnumerator.h"
 #include "nsNativeCharsetUtils.h"
 
 #include "nsISimpleEnumerator.h"
 #include "nsIComponentManager.h"
 #include "prio.h"
 #include "private/pprio.h"  // To get PR_ImportFile
-#include "prmem.h"
 #include "nsHashKeys.h"
 
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
 
 #include <direct.h>
 #include <windows.h>
 #include <shlwapi.h>
--- a/xpcom/string/nsTextFormatter.cpp
+++ b/xpcom/string/nsTextFormatter.cpp
@@ -23,17 +23,16 @@
 
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <string.h>
 #include "prdtoa.h"
 #include "mozilla/Logging.h"
 #include "mozilla/Sprintf.h"
-#include "prmem.h"
 #include "nsCRTGlue.h"
 #include "nsTextFormatter.h"
 #include "nsMemory.h"
 
 /*
 ** Note: on some platforms va_list is defined as an array,
 ** and requires array notation.
 */
@@ -88,17 +87,17 @@ struct NumArgState
 #define _LEFT		0x1
 #define _SIGNED		0x2
 #define _SPACED		0x4
 #define _ZEROS		0x8
 #define _NEG		0x10
 
 #define ELEMENTS_OF(array_) (sizeof(array_) / sizeof(array_[0]))
 
-#define PR_CHECK_DELETE(nas) if (nas && (nas != nasArray)) { PR_DELETE(nas); }
+#define FREE_IF_NECESSARY(nas) if (nas && (nas != nasArray)) { free(nas); }
 
 /*
 ** Fill into the buffer using the data in src
 */
 static int
 fill2(SprintfStateStr* aState, const char16_t* aSrc, int aSrcLen, int aWidth,
       int aFlags)
 {
@@ -757,17 +756,17 @@ BuildArgArray(const char16_t* aFmt, va_l
 
 
   /*
   ** third pass
   ** fill the nas[cn].ap
   */
   if (*aRv < 0) {
     if (nas != aNasArray) {
-      PR_DELETE(nas);
+      free(nas);
     }
     return nullptr;
   }
 
   cn = 0;
   while (cn < number) {
     if (nas[cn].type == NumArgState::UNKNOWN) {
       cn++;
@@ -795,17 +794,17 @@ BuildArgArray(const char16_t* aFmt, va_l
       case NumArgState::INTSTR:    (void)va_arg(aAp, int*);        break;
 
       case NumArgState::DOUBLE:    (void)va_arg(aAp, double);      break;
 
       case NumArgState::UNISTRING: (void)va_arg(aAp, char16_t*);   break;
 
       default:
         if (nas != aNasArray) {
-          PR_DELETE(nas);
+          free(nas);
         }
         *aRv = -1;
         va_end(aAp);
         return nullptr;
     }
     cn++;
   }
   va_end(aAp);
@@ -857,51 +856,51 @@ dosprintf(SprintfStateStr* aState, const
     return rv;
   }
 
   while ((c = *aFmt++) != 0) {
     if (c != '%') {
       rv = (*aState->stuff)(aState, aFmt - 1, 1);
       if (rv < 0) {
         va_end(aAp);
-        PR_CHECK_DELETE(nas);
+        FREE_IF_NECESSARY(nas);
         return rv;
       }
       continue;
     }
 
     /*
     ** Gobble up the % format string. Hopefully we have handled all
     ** of the strange cases!
     */
     flags = 0;
     c = *aFmt++;
     if (c == '%') {
       /* quoting a % with %% */
       rv = (*aState->stuff)(aState, aFmt - 1, 1);
       if (rv < 0) {
         va_end(aAp);
-        PR_CHECK_DELETE(nas);
+        FREE_IF_NECESSARY(nas);
         return rv;
       }
       continue;
     }
 
     if (nas) {
       /* the aFmt contains the Numbered Arguments feature */
       i = 0;
       /* should improve error check later */
       while (c && c != '$') {
         i = (i * 10) + (c - '0');
         c = *aFmt++;
       }
 
       if (nas[i - 1].type == NumArgState::UNKNOWN) {
         if (nas != nasArray) {
-          PR_DELETE(nas);
+          free(nas);
         }
         va_end(aAp);
         return -1;
       }
 
       VARARGS_ASSIGN(aAp, nas[i - 1].ap);
       c = *aFmt++;
     }
@@ -1041,17 +1040,17 @@ dosprintf(SprintfStateStr* aState, const
             }
             goto do_long;
           case NumArgState::UINT32:
             u.l = (long)va_arg(aAp, uint32_t);
           do_long:
             rv = cvt_l(aState, u.l, width, prec, radix, type, flags, hexp);
             if (rv < 0) {
               va_end(aAp);
-              PR_CHECK_DELETE(nas);
+              FREE_IF_NECESSARY(nas);
               return rv;
             }
             break;
 
           case NumArgState::INT64:
             u.ll = va_arg(aAp, int64_t);
             if (u.ll < 0) {
               u.ll = -u.ll;
@@ -1059,17 +1058,17 @@ dosprintf(SprintfStateStr* aState, const
             }
             goto do_longlong;
           case NumArgState::UINT64:
             u.ll = va_arg(aAp, uint64_t);
           do_longlong:
             rv = cvt_ll(aState, u.ll, width, prec, radix, type, flags, hexp);
             if (rv < 0) {
               va_end(aAp);
-              PR_CHECK_DELETE(nas);
+              FREE_IF_NECESSARY(nas);
               return rv;
             }
             break;
         }
         break;
 
       case 'e':
       case 'E':
@@ -1085,33 +1084,33 @@ dosprintf(SprintfStateStr* aState, const
 
       case 'c':
         u.ch = va_arg(aAp, int);
         if ((flags & _LEFT) == 0) {
           while (width-- > 1) {
             rv = (*aState->stuff)(aState, &space, 1);
             if (rv < 0) {
               va_end(aAp);
-              PR_CHECK_DELETE(nas);
+              FREE_IF_NECESSARY(nas);
               return rv;
             }
           }
         }
         rv = (*aState->stuff)(aState, &u.ch, 1);
         if (rv < 0) {
           va_end(aAp);
-          PR_CHECK_DELETE(nas);
+          FREE_IF_NECESSARY(nas);
           return rv;
         }
         if (flags & _LEFT) {
           while (width-- > 1) {
             rv = (*aState->stuff)(aState, &space, 1);
             if (rv < 0) {
               va_end(aAp);
-              PR_CHECK_DELETE(nas);
+              FREE_IF_NECESSARY(nas);
               return rv;
             }
           }
         }
         break;
 
       case 'p':
         if (sizeof(void*) == sizeof(int32_t)) {
@@ -1134,27 +1133,27 @@ dosprintf(SprintfStateStr* aState, const
         break;
 #endif
 
       case 'S':
         u.S = va_arg(aAp, const char16_t*);
         rv = cvt_S(aState, u.S, width, prec, flags);
         if (rv < 0) {
           va_end(aAp);
-          PR_CHECK_DELETE(nas);
+          FREE_IF_NECESSARY(nas);
           return rv;
         }
         break;
 
       case 's':
         u.s = va_arg(aAp, const char*);
         rv = cvt_s(aState, u.s, width, prec, flags);
         if (rv < 0) {
           va_end(aAp);
-          PR_CHECK_DELETE(nas);
+          FREE_IF_NECESSARY(nas);
           return rv;
         }
         break;
 
       case 'n':
         u.ip = va_arg(aAp, int*);
         if (u.ip) {
           *u.ip = aState->cur - aState->base;
@@ -1165,35 +1164,35 @@ dosprintf(SprintfStateStr* aState, const
         /* Not a % token after all... skip it */
 #if 0
         MOZ_ASSERT(0);
 #endif
         char16_t perct = '%';
         rv = (*aState->stuff)(aState, &perct, 1);
         if (rv < 0) {
           va_end(aAp);
-          PR_CHECK_DELETE(nas);
+          FREE_IF_NECESSARY(nas);
           return rv;
         }
         rv = (*aState->stuff)(aState, aFmt - 1, 1);
         if (rv < 0) {
           va_end(aAp);
-          PR_CHECK_DELETE(nas);
+          FREE_IF_NECESSARY(nas);
           return rv;
         }
     }
   }
 
   /* Stuff trailing NUL */
   char16_t null = '\0';
 
   rv = (*aState->stuff)(aState, &null, 1);
 
   va_end(aAp);
-  PR_CHECK_DELETE(nas);
+  FREE_IF_NECESSARY(nas);
 
   return rv;
 }
 
 /************************************************************************/
 
 static int
 StringStuff(SprintfStateStr* aState, const char16_t* aStr, uint32_t aLen)
@@ -1302,17 +1301,17 @@ nsTextFormatter::vsmprintf(const char16_
 
   ss.stuff = GrowStuff;
   ss.base = 0;
   ss.cur = 0;
   ss.maxlen = 0;
   rv = dosprintf(&ss, aFmt, aAp);
   if (rv < 0) {
     if (ss.base) {
-      PR_DELETE(ss.base);
+      free(ss.base);
     }
     return 0;
   }
   return ss.base;
 }
 
 /*
 ** Stuff routine that discards overflow data
--- a/xpcom/threads/nsProcessCommon.cpp
+++ b/xpcom/threads/nsProcessCommon.cpp
@@ -25,17 +25,16 @@
 #include "nsIObserverService.h"
 #include "nsXULAppAPI.h"
 #include "mozilla/Services.h"
 #include "GeckoProfiler.h"
 
 #include <stdlib.h>
 
 #if defined(PROCESSMODEL_WINAPI)
-#include "prmem.h"
 #include "nsString.h"
 #include "nsLiteralString.h"
 #include "nsReadableUtils.h"
 #else
 #ifdef XP_MACOSX
 #include <crt_externs.h>
 #include <spawn.h>
 #include <sys/wait.h>
@@ -147,17 +146,17 @@ assembleCmdLine(char* const* aArgv, wcha
      * may double.  If we quote an argument, that needs two ".
      * Finally, we need a space between arguments, and
      * a null byte at the end of command line.
      */
     cmdLineSize += 2 * strlen(*arg)  /* \ and " need to be escaped */
                    + 2               /* we quote every argument */
                    + 1;              /* space in between, or final null */
   }
-  p = cmdLine = (char*)PR_MALLOC(cmdLineSize * sizeof(char));
+  p = cmdLine = (char*) malloc(cmdLineSize * sizeof(char));
   if (!p) {
     return -1;
   }
 
   for (arg = aArgv; *arg; ++arg) {
     /* Add a space to separates the arguments */
     if (arg != aArgv) {
       *p++ = ' ';
@@ -222,19 +221,19 @@ assembleCmdLine(char* const* aArgv, wcha
     }
     if (argNeedQuotes) {
       *p++ = '"';
     }
   }
 
   *p = '\0';
   int32_t numChars = MultiByteToWideChar(aCodePage, 0, cmdLine, -1, nullptr, 0);
-  *aWideCmdLine = (wchar_t*)PR_MALLOC(numChars * sizeof(wchar_t));
+  *aWideCmdLine = (wchar_t*) malloc(numChars * sizeof(wchar_t));
   MultiByteToWideChar(aCodePage, 0, cmdLine, -1, *aWideCmdLine, numChars);
-  PR_Free(cmdLine);
+  free(cmdLine);
   return 0;
 }
 #endif
 
 void
 nsProcess::Monitor(void* aArg)
 {
   char stackBaseGuess;
@@ -501,17 +500,17 @@ nsProcess::RunProcess(bool aBlocking, ch
   retVal = ShellExecuteExW(&sinfo);
   if (!retVal) {
     return NS_ERROR_FILE_EXECUTION_FAILED;
   }
 
   mProcess = sinfo.hProcess;
 
   if (cmdLine) {
-    PR_Free(cmdLine);
+    free(cmdLine);
   }
 
   mPid = GetProcessId(mProcess);
 #elif defined(XP_MACOSX)
   // Initialize spawn attributes.
   posix_spawnattr_t spawnattr;
   if (posix_spawnattr_init(&spawnattr) != 0) {
     return NS_ERROR_FAILURE;