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.
This commit is contained in:
Nicholas Nethercote
2017-06-30 19:05:41 -07:00
parent a8cada8c08
commit fcd4f4fa21
69 changed files with 158 additions and 198 deletions

View File

@@ -51,7 +51,6 @@
#include "nsIArray.h"
#include "nsIObjectInputStream.h"
#include "nsIObjectOutputStream.h"
#include "prmem.h"
#include "WrapperFactory.h"
#include "nsGlobalWindow.h"
#include "nsScriptNameSpaceManager.h"

View File

@@ -323,6 +323,8 @@ FileReader::DoReadData(uint64_t 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;

View File

@@ -200,7 +200,7 @@ AndroidMediaPluginHost::AndroidMediaPluginHost() {
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);

View File

@@ -66,10 +66,10 @@ FFVPXRuntimeLinker::Init()
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) {

View File

@@ -11,7 +11,6 @@
#include "Layers.h"
#include "ImageContainer.h"
#include "ImageTypes.h"
#include "prmem.h"
#include "nsContentUtils.h"
#include "MediaStreamGraph.h"
@@ -148,7 +147,7 @@ static void AllocateSolidColorFrame(layers::PlanarYCbCrData& aData,
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);
@@ -168,7 +167,7 @@ static void AllocateSolidColorFrame(layers::PlanarYCbCrData& aData,
static void ReleaseFrame(layers::PlanarYCbCrData& aData)
{
PR_Free(aData.mYChannel);
free(aData.mYChannel);
}
nsresult

View File

@@ -22,7 +22,6 @@
#include "nsIXPConnect.h"
#include "xpcpublic.h"
#include "nsIDOMElement.h"
#include "prmem.h"
#include "nsIContent.h"
#include "nsPluginInstanceOwner.h"
#include "nsWrapperCacheInlines.h"
@@ -1044,7 +1043,7 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray,
}
*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;
@@ -1053,7 +1052,7 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray,
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;
}
@@ -1062,7 +1061,7 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray,
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);
@@ -1499,7 +1498,7 @@ CallNPMethodInternal(JSContext *cx, JS::Handle<JSObject*> obj, unsigned argc,
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!");
@@ -1515,7 +1514,7 @@ CallNPMethodInternal(JSContext *cx, JS::Handle<JSObject*> obj, unsigned argc,
ThrowJSExceptionASCII(cx, "Error converting jsvals to NPVariants!");
if (npargs != npargs_buf) {
PR_Free(npargs);
free(npargs);
}
return false;
@@ -1577,7 +1576,7 @@ CallNPMethodInternal(JSContext *cx, JS::Handle<JSObject*> obj, unsigned argc,
}
if (npargs != npargs_buf) {
PR_Free(npargs);
free(npargs);
}
if (!ok) {
@@ -1646,7 +1645,7 @@ NPObjWrapper_NewEnumerate(JSContext *cx, JS::Handle<JSObject*> obj,
properties.infallibleAppend(id);
}
PR_Free(identifiers);
free(identifiers);
return true;
}
@@ -2016,7 +2015,7 @@ nsJSNPRuntime::OnPluginDestroy(NPP npp)
if (npobj->_class && npobj->_class->deallocate) {
npobj->_class->deallocate(npobj);
} else {
PR_Free(npobj);
free(npobj);
}
::JS_SetPrivate(entry->mJSObj, nullptr);
@@ -2085,7 +2084,7 @@ CreateNPObjectMember(NPP npp, JSContext *cx, JSObject *obj, NPObject* npobj,
}
NPObjectMemberPrivate* memberPrivate =
(NPObjectMemberPrivate *)PR_Malloc(sizeof(NPObjectMemberPrivate));
(NPObjectMemberPrivate*) malloc(sizeof(NPObjectMemberPrivate));
if (!memberPrivate)
return false;
@@ -2095,7 +2094,7 @@ CreateNPObjectMember(NPP npp, JSContext *cx, JSObject *obj, NPObject* npobj,
JSObject *memobj = ::JS_NewObject(cx, &sNPObjectMemberClass);
if (!memobj) {
PR_Free(memberPrivate);
free(memberPrivate);
return false;
}
@@ -2170,7 +2169,7 @@ NPObjectMember_Finalize(JSFreeOp *fop, JSObject *obj)
if (!memberPrivate)
return;
PR_Free(memberPrivate);
free(memberPrivate);
}
static bool
@@ -2200,7 +2199,7 @@ NPObjectMember_Call(JSContext *cx, unsigned argc, JS::Value *vp)
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!");
@@ -2215,7 +2214,7 @@ NPObjectMember_Call(JSContext *cx, unsigned argc, JS::Value *vp)
ThrowJSExceptionASCII(cx, "Error converting jsvals to NPVariants!");
if (npargs != npargs_buf) {
PR_Free(npargs);
free(npargs);
}
return false;
@@ -2234,7 +2233,7 @@ NPObjectMember_Call(JSContext *cx, unsigned argc, JS::Value *vp)
}
if (npargs != npargs_buf) {
PR_Free(npargs);
free(npargs);
}
if (!ok) {

View File

@@ -9,7 +9,6 @@
#include "mozilla/ArrayUtils.h"
#include "pratom.h"
#include "prmem.h"
#include "prenv.h"
#include "prclist.h"
@@ -1173,7 +1172,7 @@ _createobject(NPP npp, NPClass* aClass)
if (aClass->allocate) {
npobj = aClass->allocate(npp, aClass);
} else {
npobj = (NPObject *)PR_Malloc(sizeof(NPObject));
npobj = (NPObject*) malloc(sizeof(NPObject));
}
if (npobj) {
@@ -1237,7 +1236,7 @@ _releaseobject(NPObject* npobj)
if (npobj->_class && npobj->_class->deallocate) {
npobj->_class->deallocate(npobj);
} else {
PR_Free(npobj);
free(npobj);
}
}
}
@@ -1648,7 +1647,7 @@ _releasevariantvalue(NPVariant* 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;

View File

@@ -11,7 +11,6 @@
#endif
#include "mozilla/Logging.h"
#include "prmem.h"
#include "nscore.h"
#include "prenv.h"
@@ -167,7 +166,7 @@ nsNPAPIPluginInstance::~nsNPAPIPluginInstance()
#endif
if (mMIMEType) {
PR_Free((void *)mMIMEType);
free(mMIMEType);
mMIMEType = nullptr;
}

View File

@@ -5,7 +5,6 @@
#include "nsNPAPIPluginStreamListener.h"
#include "plstr.h"
#include "prmem.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsIFile.h"
@@ -169,7 +168,7 @@ nsNPAPIPluginStreamListener::~nsNPAPIPluginStreamListener()
// lets get rid of the buffer
if (mStreamBuffer) {
PR_Free(mStreamBuffer);
free(mStreamBuffer);
mStreamBuffer=nullptr;
}
@@ -500,7 +499,7 @@ nsNPAPIPluginStreamListener::OnDataAvailable(nsPluginStreamListenerPeer* streamP
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;
}
@@ -546,7 +545,7 @@ nsNPAPIPluginStreamListener::OnDataAvailable(nsPluginStreamListenerPeer* streamP
// 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;

View File

@@ -11,7 +11,6 @@
#include <cstdlib>
#include <stdio.h>
#include "prio.h"
#include "prmem.h"
#include "nsNPAPIPlugin.h"
#include "nsNPAPIPluginStreamListener.h"
#include "nsNPAPIPluginInstance.h"

View File

@@ -8,7 +8,6 @@
#include "nsIMemory.h"
#include "nsPluginsDir.h"
#include "nsPluginsDirUtils.h"
#include "prmem.h"
#include "prenv.h"
#include "prerror.h"
#include "prio.h"
@@ -404,9 +403,12 @@ nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
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);

View File

@@ -8,7 +8,6 @@
#include "nsPluginsDir.h"
#include "nsTArray.h"
#include "prmem.h"
///////////////////////////////////////////////////////////////////////////////
// Output format from NPP_GetMIMEDescription: "...mime type[;version]:[extension]:[desecription];..."
@@ -67,9 +66,9 @@ ParsePluginMimeDescription(const char *mdesc, nsPluginInfo &info)
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++) {
@@ -82,7 +81,7 @@ ParsePluginMimeDescription(const char *mdesc, nsPluginInfo &info)
rv = NS_OK;
}
if (mdescDup)
PR_Free(mdescDup);
PL_strfree(mdescDup);
return rv;
}

View File

@@ -18,7 +18,6 @@
#include "nsPluginsDir.h"
#include "prlink.h"
#include "plstr.h"
#include "prmem.h"
#include "windows.h"
#include "winbase.h"
@@ -151,7 +150,7 @@ static char** MakeStringArray(uint32_t variants, char* data)
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;
@@ -189,7 +188,7 @@ static void FreeStringArray(uint32_t variants, char ** array)
array[i] = nullptr;
}
}
PR_Free(array);
free(array);
}
static bool CanLoadPlugin(char16ptr_t aBinaryPath)
@@ -363,7 +362,7 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info, PRLibrary **outLibrary)
versionsize = ::GetFileVersionInfoSizeW(lpFilepath, &zerome);
if (versionsize > 0)
verbuf = PR_Malloc(versionsize);
verbuf = malloc(versionsize);
if (!verbuf)
return NS_ERROR_OUT_OF_MEMORY;
@@ -396,7 +395,7 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info, PRLibrary **outLibrary)
rv = NS_ERROR_FAILURE;
}
PR_Free(verbuf);
free(verbuf);
return rv;
}

View File

@@ -31,7 +31,6 @@
#include "nsIContentViewer.h"
#include "prtime.h"
#include "mozilla/Logging.h"
#include "prmem.h"
#include "nsRect.h"
#include "nsIWebNavigation.h"
#include "nsIScriptElement.h"

View File

@@ -10,7 +10,6 @@
#include "txCore.h"
#include "nsCollationCID.h"
#include "nsIServiceManager.h"
#include "prmem.h"
#define kAscending (1<<0)
#define kUpperFirst (1<<1)
@@ -160,9 +159,9 @@ txResultStringComparator::StringValue::StringValue() : mKey(0),
txResultStringComparator::StringValue::~StringValue()
{
PR_Free(mKey);
free(mKey);
if (mCaseLength > 0)
PR_Free((uint8_t*)mCaseKey);
free(mCaseKey);
else
delete (nsString*)mCaseKey;
}

View File

@@ -42,7 +42,6 @@
#include "nsReadableUtils.h"
#include "nsXULElement.h"
#include "mozilla/Logging.h"
#include "prmem.h"
#include "nsCRT.h"
#include "nsXULPrototypeDocument.h" // XXXbe temporary

View File

@@ -588,7 +588,7 @@ nsHttpNegotiateAuth::GenerateCredentials(nsIHttpAuthenticableChannel *authChanne
else
snprintf(*creds, bufsize, "%s %s", kNegotiate, encoded_token);
PR_Free(encoded_token);
PR_Free(encoded_token); // PL_Base64Encode() uses PR_Malloc().
return rv;
}

View File

@@ -9,7 +9,6 @@
#include "nsIFileStreams.h"
#include "nsThreadUtils.h"
#include "nsAppDirectoryServiceDefs.h"
#include "prmem.h"
#include "nsIObserverService.h"
#include "nsLiteralString.h"
#include "nsIPromptService.h"
@@ -414,7 +413,7 @@ nsresult nsAutoConfig::evaluateLocalFile(nsIFile *file)
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));
char* buf = (char*) malloc(fs * sizeof(char));
if (!buf)
return NS_ERROR_OUT_OF_MEMORY;
@@ -425,7 +424,7 @@ nsresult nsAutoConfig::evaluateLocalFile(nsIFile *file)
true, false);
}
inStr->Close();
PR_Free(buf);
free(buf);
return rv;
}

View File

@@ -19,7 +19,6 @@
#include "nsToolkitCompsCID.h"
#include "nsXPIDLString.h"
#include "nsNetUtil.h"
#include "prmem.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nspr.h"
@@ -272,12 +271,12 @@ nsresult nsReadConfig::openAndEvaluateJSFile(const char *aFileName, int32_t obsc
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));
char* buf = (char*) malloc(fs * sizeof(char));
if (!buf)
return NS_ERROR_OUT_OF_MEMORY;
@@ -295,7 +294,7 @@ nsresult nsReadConfig::openAndEvaluateJSFile(const char *aFileName, int32_t obsc
isEncoded ? true:false);
}
inStr->Close();
PR_Free(buf);
free(buf);
return rv;
}

View File

@@ -4,7 +4,6 @@
* 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)
@@ -13,7 +12,7 @@ bool nsCharSetProber::FilterWithoutEnglishLetters(const char* aBuf, uint32_t aLe
char *prevPtr, *curPtr;
bool meetMSB = false;
newptr = *newBuf = (char*)PR_Malloc(aLen);
newptr = *newBuf = (char*)malloc(aLen);
if (!newptr)
return false;
@@ -54,7 +53,7 @@ bool nsCharSetProber::FilterWithEnglishLetters(const char* aBuf, uint32_t aLen,
char *prevPtr, *curPtr;
bool isInTag = false;
newptr = *newBuf = (char*)PR_Malloc(aLen);
newptr = *newBuf = (char*)malloc(aLen);
if (!newptr)
return false;

View File

@@ -32,7 +32,7 @@ public:
// 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);

View File

@@ -4,7 +4,6 @@
* 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
@@ -106,7 +105,7 @@ nsProbingState nsLatin1Prober::HandleData(const char* aBuf, uint32_t aLen)
}
if (newBuf1 != aBuf)
PR_FREEIF(newBuf1);
free(newBuf1);
return mState;
}

View File

@@ -6,7 +6,6 @@
#include <math.h>
#include "prlink.h"
#include "prmem.h"
#include "prenv.h"
#include "gfxPrefs.h"
#include "nsString.h"

View File

@@ -6,7 +6,6 @@
#include <math.h>
#include "prlink.h"
#include "prmem.h"
#include "prenv.h"
#include "gfxPrefs.h"
#include "nsString.h"

View File

@@ -11,7 +11,6 @@
#include "prlink.h"
#include "prmem.h"
#include "prenv.h"
#include "gfxPrefs.h"
#include "nsString.h"

View File

@@ -6,7 +6,6 @@
#include <math.h>
#include "prlink.h"
#include "prmem.h"
#include "prenv.h"
#include "gfxPrefs.h"
#include "nsString.h"

View File

@@ -109,7 +109,8 @@ nsJPEGDecoder::~nsJPEGDecoder()
mInfo.src = nullptr;
jpeg_destroy_decompress(&mInfo);
PR_FREEIF(mBackBuffer);
free(mBackBuffer);
mBackBuffer = nullptr;
if (mTransform) {
qcms_transform_release(mTransform);
}
@@ -904,7 +905,7 @@ fill_input_buffer (j_decompress_ptr jd)
// 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;

View File

@@ -5,7 +5,6 @@
#include "nsCollation.h"
#include "nsIServiceManager.h"
#include "prmem.h"
#include "nsString.h"
NS_IMPL_ISUPPORTS(nsCollation, nsICollation)
@@ -142,8 +141,8 @@ nsCollation::AllocateRawSortKey(int32_t strength, const nsAString& stringIn,
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;
}

View File

@@ -6,7 +6,6 @@
#include "nsCollation.h"
#include "nsCOMPtr.h"
#include "nsUnicharUtils.h"
#include "prmem.h"
#include <string.h>
@@ -63,7 +62,7 @@ nsCollation::AllocateRawSortKey(int32_t strength,
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;

View File

@@ -5,7 +5,6 @@
// found in the LICENSE file.
#include "base/logging.h"
#include "prmem.h"
#include "base/string_util.h"
#include "nsXPCOM.h"
#include "mozilla/Move.h"

View File

@@ -81,9 +81,9 @@ bool LaunchApp(const std::vector<std::string>& argv,
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];

View File

@@ -22,7 +22,6 @@
#include "mozilla/UniquePtr.h"
#include "prenv.h"
#include "prmem.h"
#ifdef MOZ_WIDGET_GONK
/*
@@ -64,7 +63,7 @@ public:
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;
}
@@ -75,7 +74,7 @@ public:
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;
@@ -87,9 +86,9 @@ public:
return;
}
for (char **e = mEnvp; *e; ++e) {
PR_Free(*e);
free(*e);
}
PR_Free(mEnvp);
free(mEnvp);
}
char * const *AsEnvp() { return mEnvp; }

View File

@@ -18,7 +18,6 @@ using namespace std;
#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"
@@ -785,7 +784,7 @@ class TransportConduitTest : public ::testing::Test
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,
@@ -794,7 +793,7 @@ class TransportConduitTest : public ::testing::Test
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();

View File

@@ -179,7 +179,7 @@ Fake_VideoStreamSource::Notify(nsITimer* aTimer)
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;
@@ -213,11 +213,11 @@ mozilla::layers::BufferRecycleBin::BufferRecycleBin() :
}
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)

View File

@@ -14,7 +14,6 @@
#include "prerror.h"
#include "plstr.h"
#include "prmem.h"
#include <jni.h>

View File

@@ -269,7 +269,7 @@ NetworkActivityMonitor::AttachIOLayer(PRFileDesc *fd)
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;
}

View File

@@ -73,7 +73,7 @@ nsresult mozilla::net::AttachShutdownLayer(PRFileDesc *aFd)
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;

View File

@@ -351,7 +351,7 @@ AttachTCPFastOpenIOLayer(PRFileDesc *fd)
if (status == PR_FAILURE) {
delete secret;
PR_DELETE(layer);
PR_Free(layer); // PR_CreateIOLayerStub() uses PR_Malloc().
return NS_ERROR_FAILURE;
}
return NS_OK;

View File

@@ -60,7 +60,7 @@ nsBase64Encoder::Finish(nsACString& result)
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;

View File

@@ -89,7 +89,7 @@ nsDiskCacheMap::Open(nsIFile * cacheDirectory,
mHeader.mVersion = nsDiskCache::kCurrentVersion;
mHeader.mRecordCount = kMinRecordCount;
mRecordArray = (nsDiskCacheRecord*)
PR_CALLOC(mHeader.mRecordCount * sizeof(nsDiskCacheRecord));
calloc(mHeader.mRecordCount, sizeof(nsDiskCacheRecord));
if (!mRecordArray) {
*corruptInfo = nsDiskCache::kOutOfMemory;
rv = NS_ERROR_OUT_OF_MEMORY;
@@ -131,7 +131,7 @@ nsDiskCacheMap::Open(nsIFile * cacheDirectory,
}
// 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;
@@ -230,8 +230,10 @@ nsDiskCacheMap::Close(bool flush)
mCleanFD = nullptr;
}
PR_FREEIF(mRecordArray);
PR_FREEIF(mBuffer);
free(mRecordArray);
mRecordArray = nullptr;
free(mBuffer);
mBuffer = nullptr;
mBufferSize = 0;
return rv;
}
@@ -349,7 +351,7 @@ nsDiskCacheMap::GrowRecords()
if (newCount > mMaxRecordCount)
newCount = mMaxRecordCount;
nsDiskCacheRecord* newArray = (nsDiskCacheRecord *)
PR_REALLOC(mRecordArray, newCount * sizeof(nsDiskCacheRecord));
realloc(mRecordArray, newCount * sizeof(nsDiskCacheRecord));
if (!newArray)
return NS_ERROR_OUT_OF_MEMORY;
@@ -414,7 +416,7 @@ nsDiskCacheMap::ShrinkRecords()
// 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;
@@ -1191,7 +1193,7 @@ 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;

View File

@@ -5,7 +5,6 @@
* 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"
@@ -972,7 +971,7 @@ 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) {
@@ -1010,7 +1009,7 @@ char *DecodeQ(const char *in, uint32_t length)
return dest;
badsyntax:
PR_Free(dest);
free(dest);
return nullptr;
}
@@ -1146,7 +1145,7 @@ nsresult DecodeQOrBase64Str(const char *aEncoded, size_t aLen, char aQOrBase64,
IS_7BIT_NON_ASCII_CHARSET(aCharset),
true, 1, utf8Text);
}
PR_Free(decodedText);
free(decodedText);
if (NS_FAILED(rv)) {
return rv;
}

View File

@@ -2869,7 +2869,7 @@ WebSocketChannel::SetupRequest()
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));

View File

@@ -711,7 +711,7 @@ nsNamedPipeClose(PRFileDesc* aFd)
}
MOZ_ASSERT(!aFd->lower);
PR_DELETE(aFd);
PR_Free(aFd); // PRFileDescs are allocated with PR_Malloc().
return PR_SUCCESS;
}

View File

@@ -1572,7 +1572,7 @@ nsSOCKSIOLayerAddToSocket(int32_t family,
{
// clean up IOLayerStub
LOGERROR(("Failed to create nsSOCKSSocketInfo()."));
PR_DELETE(layer);
PR_Free(layer); // PR_CreateIOLayerStub() uses PR_Malloc().
return NS_ERROR_FAILURE;
}
@@ -1593,7 +1593,7 @@ nsSOCKSIOLayerAddToSocket(int32_t family,
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;
}

View File

@@ -15,7 +15,6 @@
#include "nsIUnicharInputStream.h"
#include "nsIProtocolHandler.h"
#include "nsNetUtil.h"
#include "prmem.h"
#include "nsTextFormatter.h"
#include "nsDirectoryServiceDefs.h"
#include "nsCRT.h"
@@ -1228,11 +1227,10 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
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' };

View File

@@ -747,7 +747,7 @@ RDFContentSinkImpl::AddText(const char16_t* aText, int32_t aLength)
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);

View File

@@ -52,7 +52,6 @@
#include "plstr.h"
#include "mozilla/Logging.h"
#include "prprf.h"
#include "prmem.h"
#include "rdf.h"
#include "nsCRT.h"
#include "nsCRTGlue.h"
@@ -83,19 +82,19 @@ class BlobImpl;
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
@@ -103,7 +102,7 @@ DataSourceFreeEntry(void *pool, PLHashEntry *he, unsigned flag)
{
if (flag == HT_FREE_ENTRY) {
PL_strfree((char*) he->key);
PR_Free(he);
free(he);
}
}

View File

@@ -29,7 +29,6 @@
#include "pkix/pkix.h"
#include "pkix/pkixnss.h"
#include "prerror.h"
#include "prmem.h"
#include "secerr.h"
#include "CNNICHashWhitelist.inc"

View File

@@ -39,7 +39,6 @@
#include "pkix/pkixtypes.h"
#include "pkix/Result.h"
#include "prerror.h"
#include "prmem.h"
#include "secasn1.h"
#include "secder.h"
#include "secerr.h"

View File

@@ -55,6 +55,7 @@
#include "ssl.h"
#include "sslerr.h"
#include "sslproto.h"
#include "prmem.h"
#ifndef MOZ_NO_SMART_CARDS
#include "nsSmartCardMonitor.h"
@@ -1101,7 +1102,7 @@ nsNSSComponent::LoadLoadableRoots()
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)))) {

View File

@@ -1874,7 +1874,7 @@ nsConvertCANamesToStrings(const UniquePLArenaPool& arena, char** caNameStrings,
// 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;
}
@@ -1882,7 +1882,7 @@ nsConvertCANamesToStrings(const UniquePLArenaPool& arena, char** caNameStrings,
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;
}
@@ -1892,7 +1892,7 @@ nsConvertCANamesToStrings(const UniquePLArenaPool& arena, char** caNameStrings,
(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;
}
@@ -1911,21 +1911,21 @@ nsConvertCANamesToStrings(const UniquePLArenaPool& arena, char** caNameStrings,
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;
}

View File

@@ -18,7 +18,6 @@
#include "nsReadableUtils.h"
#include "nsThreadUtils.h"
#include "pkix/pkixtypes.h"
#include "prmem.h"
#include "secerr.h"
using namespace mozilla;

View File

@@ -242,8 +242,8 @@ SmartCardMonitoringThread::SetTokenName(CK_SLOT_ID slotid,
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) {

View File

@@ -84,7 +84,6 @@ using mozilla::InjectCrashRunnable;
#include <time.h>
#include <prenv.h>
#include <prio.h>
#include <prmem.h>
#include "mozilla/Mutex.h"
#include "nsDebug.h"
#include "nsCRT.h"

View File

@@ -110,7 +110,7 @@ nsUnixSystemProxySettings::GetProxyForURI(const nsACString & aSpec,
c++;
}
PR_Free(proxyArray);
free(proxyArray);
return NS_OK;
}

View File

@@ -43,7 +43,6 @@
#include <sys/sysctl.h>
#endif
#include "prmem.h"
#include "prnetdb.h"
#include "prprf.h"
#include "prproces.h"

View File

@@ -4,7 +4,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsDecodeAppleFile.h"
#include "prmem.h"
#include "nsCRT.h"
@@ -20,7 +19,7 @@ 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;
@@ -35,8 +34,8 @@ nsDecodeAppleFile::nsDecodeAppleFile()
nsDecodeAppleFile::~nsDecodeAppleFile()
{
PR_FREEIF(m_dataBuffer);
free(m_dataBuffer);
m_dataBuffer = nullptr;
if (m_entries)
delete [] m_entries;
}

View File

@@ -7,7 +7,6 @@
#include <stdio.h>
#include "nsBidiKeyboard.h"
#include "WidgetUtils.h"
#include "prmem.h"
#include <tchar.h>
NS_IMPL_ISUPPORTS(nsBidiKeyboard, nsIBidiKeyboard)
@@ -102,13 +101,13 @@ nsresult nsBidiKeyboard::SetupBidiKeyboards()
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;
}
@@ -126,7 +125,7 @@ nsresult nsBidiKeyboard::SetupBidiKeyboards()
isLTRKeyboardSet = true;
}
}
PR_Free(buf);
free(buf);
mInitialized = true;
// If there is not at least one keyboard of each directionality, Bidi

View File

@@ -12,8 +12,6 @@
#include "mozilla/Preferences.h"
#include "mozilla/RefPtr.h"
#include "prmem.h"
#include <winspool.h>
#include "nsIWidget.h"
@@ -225,13 +223,13 @@ static void CleanAndCopyString(wchar_t*& aStr, const wchar_t* aNewStr)
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);
}
}

View File

@@ -12,7 +12,6 @@
#include "nsITransferable.h"
#include "nsGfxCIID.h"
#include "nsMemory.h"
#include "prmem.h"
#include "imgIEncoder.h"
#include "nsLiteralString.h"
#include "nsComponentManagerUtils.h"

View File

@@ -23,7 +23,6 @@
#include "mozilla/Logging.h"
#include "prtime.h"
#include "prmem.h"
#include "nsNativeCharsetUtils.h"
#include "nsThreadUtils.h"

View File

@@ -80,7 +80,6 @@
#include "mozilla/Logging.h"
#include "prtime.h"
#include "prmem.h"
#include "prenv.h"
#include "mozilla/WidgetTraceEvent.h"

View File

@@ -37,7 +37,6 @@ using mozilla::plugins::PluginInstanceParent;
#include "mozilla/UniquePtrExtensions.h"
#include "nsGfxCIID.h"
#include "gfxContext.h"
#include "prmem.h"
#include "WinUtils.h"
#include "nsIWidgetListener.h"
#include "mozilla/Unused.h"
@@ -556,7 +555,7 @@ nsresult nsWindowGfx::CreateIcon(imgIContainer *aContainer,
}
HBITMAP mbmp = DataToBitmap(a1data, iconSize.width, -iconSize.height, 1);
PR_Free(a1data);
free(a1data);
ICONINFO info = {0};
info.fIcon = !aIsCursor;
@@ -583,7 +582,7 @@ uint8_t* nsWindowGfx::Data32BitTo1Bit(uint8_t* aImageData,
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;

View File

@@ -10,7 +10,6 @@
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/Sprintf.h"
#include "XRemoteClient.h"
#include "prmem.h"
#include "plstr.h"
#include "prsystem.h"
#include "mozilla/Logging.h"

View File

@@ -50,7 +50,6 @@
////////////////////////////////////////////////////////////////////////////////
#include "plhash.h"
#include "prmem.h"
#include "prthread.h"
@@ -188,19 +187,19 @@ AssertActivityIsLegal()
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
@@ -208,7 +207,7 @@ SerialNumberFreeEntry(void* aPool, PLHashEntry* aHashEntry, unsigned aFlag)
{
if (aFlag == HT_FREE_ENTRY) {
delete static_cast<SerialNumberRecord*>(aHashEntry->value);
PR_Free(aHashEntry);
free(aHashEntry);
}
}
@@ -217,7 +216,7 @@ 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);
}
}
@@ -392,7 +391,7 @@ 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);
}
}

View File

@@ -1908,7 +1908,7 @@ nsLocalFile::SetPersistentDescriptor(const nsACString& aPersistentDescriptor)
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;
}
@@ -1920,7 +1920,7 @@ nsLocalFile::SetPersistentDescriptor(const nsACString& aPersistentDescriptor)
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;
}

View File

@@ -21,7 +21,6 @@
#include "nsIComponentManager.h"
#include "prio.h"
#include "private/pprio.h" // To get PR_ImportFile
#include "prmem.h"
#include "nsHashKeys.h"
#include "nsXPIDLString.h"

View File

@@ -28,7 +28,6 @@
#include "prdtoa.h"
#include "mozilla/Logging.h"
#include "mozilla/Sprintf.h"
#include "prmem.h"
#include "nsCRTGlue.h"
#include "nsTextFormatter.h"
#include "nsMemory.h"
@@ -93,7 +92,7 @@ struct NumArgState
#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
@@ -762,7 +761,7 @@ BuildArgArray(const char16_t* aFmt, va_list aAp, int* aRv,
*/
if (*aRv < 0) {
if (nas != aNasArray) {
PR_DELETE(nas);
free(nas);
}
return nullptr;
}
@@ -800,7 +799,7 @@ BuildArgArray(const char16_t* aFmt, va_list aAp, int* aRv,
default:
if (nas != aNasArray) {
PR_DELETE(nas);
free(nas);
}
*aRv = -1;
va_end(aAp);
@@ -862,7 +861,7 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
rv = (*aState->stuff)(aState, aFmt - 1, 1);
if (rv < 0) {
va_end(aAp);
PR_CHECK_DELETE(nas);
FREE_IF_NECESSARY(nas);
return rv;
}
continue;
@@ -879,7 +878,7 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
rv = (*aState->stuff)(aState, aFmt - 1, 1);
if (rv < 0) {
va_end(aAp);
PR_CHECK_DELETE(nas);
FREE_IF_NECESSARY(nas);
return rv;
}
continue;
@@ -896,7 +895,7 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
if (nas[i - 1].type == NumArgState::UNKNOWN) {
if (nas != nasArray) {
PR_DELETE(nas);
free(nas);
}
va_end(aAp);
return -1;
@@ -1046,7 +1045,7 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
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;
@@ -1064,7 +1063,7 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
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;
@@ -1090,7 +1089,7 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
rv = (*aState->stuff)(aState, &space, 1);
if (rv < 0) {
va_end(aAp);
PR_CHECK_DELETE(nas);
FREE_IF_NECESSARY(nas);
return rv;
}
}
@@ -1098,7 +1097,7 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
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) {
@@ -1106,7 +1105,7 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
rv = (*aState->stuff)(aState, &space, 1);
if (rv < 0) {
va_end(aAp);
PR_CHECK_DELETE(nas);
FREE_IF_NECESSARY(nas);
return rv;
}
}
@@ -1139,7 +1138,7 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
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;
@@ -1149,7 +1148,7 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
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;
@@ -1170,13 +1169,13 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
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;
}
}
@@ -1188,7 +1187,7 @@ dosprintf(SprintfStateStr* aState, const char16_t* aFmt, va_list aAp)
rv = (*aState->stuff)(aState, &null, 1);
va_end(aAp);
PR_CHECK_DELETE(nas);
FREE_IF_NECESSARY(nas);
return rv;
}
@@ -1307,7 +1306,7 @@ nsTextFormatter::vsmprintf(const char16_t* aFmt, va_list aAp)
rv = dosprintf(&ss, aFmt, aAp);
if (rv < 0) {
if (ss.base) {
PR_DELETE(ss.base);
free(ss.base);
}
return 0;
}

View File

@@ -30,7 +30,6 @@
#include <stdlib.h>
#if defined(PROCESSMODEL_WINAPI)
#include "prmem.h"
#include "nsString.h"
#include "nsLiteralString.h"
#include "nsReadableUtils.h"
@@ -152,7 +151,7 @@ assembleCmdLine(char* const* aArgv, wchar_t** aWideCmdLine, UINT aCodePage)
+ 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;
}
@@ -227,9 +226,9 @@ assembleCmdLine(char* const* aArgv, wchar_t** aWideCmdLine, UINT aCodePage)
*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
@@ -506,7 +505,7 @@ nsProcess::RunProcess(bool aBlocking, char** aMyArgv, nsIObserver* aObserver,
mProcess = sinfo.hProcess;
if (cmdLine) {
PR_Free(cmdLine);
free(cmdLine);
}
mPid = GetProcessId(mProcess);