Skip to content

Commit

Permalink
Bug 1138293 - Use malloc/free/realloc/calloc instead of moz_malloc/mo…
Browse files Browse the repository at this point in the history
…z_free/moz_realloc/moz_calloc. r=njn

The distinction between moz_malloc/moz_free and malloc/free is not
interesting. We are inconsistent in our use of one or the other, and
I wouldn't be surprised if we are mixing them anyways.
  • Loading branch information
glandium committed Mar 31, 2015
1 parent 8e094d5 commit 20130cf
Show file tree
Hide file tree
Showing 71 changed files with 199 additions and 200 deletions.
4 changes: 2 additions & 2 deletions dom/base/BlobSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BlobSet {

~BlobSet()
{
moz_free(mData);
free(mData);
}

nsresult AppendVoidPtr(const void* aData, uint32_t aLength);
Expand Down Expand Up @@ -52,7 +52,7 @@ class BlobSet {
if (!bufferLen.isValid())
return false;

void* data = moz_realloc(mData, bufferLen.value());
void* data = realloc(mData, bufferLen.value());
if (!data)
return false;

Expand Down
6 changes: 3 additions & 3 deletions dom/base/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ class File final : public nsIDOMFile
uint64_t aLength);

// The returned File takes ownership of aMemoryBuffer. aMemoryBuffer will be
// freed by moz_free so it must be allocated by moz_malloc or something
// freed by free so it must be allocated by malloc or something
// compatible with it.
static already_AddRefed<File>
CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength,
const nsAString& aName, const nsAString& aContentType,
uint64_t aLastModifiedDate);

// The returned File takes ownership of aMemoryBuffer. aMemoryBuffer will be
// freed by moz_free so it must be allocated by moz_malloc or something
// freed by free so it must be allocated by malloc or something
// compatible with it.
static already_AddRefed<File>
CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength,
Expand Down Expand Up @@ -552,7 +552,7 @@ class FileImplMemory final : public FileImplBase
sDataOwners = nullptr;
}

moz_free(mData);
free(mData);
}

public:
Expand Down
8 changes: 4 additions & 4 deletions dom/base/nsAttrAndChildArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ nsAttrAndChildArray::~nsAttrAndChildArray()

Clear();

moz_free(mImpl);
free(mImpl);
}

nsIContent*
Expand Down Expand Up @@ -635,11 +635,11 @@ nsAttrAndChildArray::Compact()
// Then resize or free buffer
uint32_t newSize = attrCount * ATTRSIZE + childCount;
if (!newSize && !mImpl->mMappedAttrs) {
moz_free(mImpl);
free(mImpl);
mImpl = nullptr;
}
else if (newSize < mImpl->mBufferSize) {
mImpl = static_cast<Impl*>(moz_realloc(mImpl, (newSize + NS_IMPL_EXTRA_SIZE) * sizeof(nsIContent*)));
mImpl = static_cast<Impl*>(realloc(mImpl, (newSize + NS_IMPL_EXTRA_SIZE) * sizeof(nsIContent*)));
NS_ASSERTION(mImpl, "failed to reallocate to smaller buffer");

mImpl->mBufferSize = newSize;
Expand Down Expand Up @@ -776,7 +776,7 @@ nsAttrAndChildArray::GrowBy(uint32_t aGrowSize)
}

bool needToInitialize = !mImpl;
Impl* newImpl = static_cast<Impl*>(moz_realloc(mImpl, size * sizeof(void*)));
Impl* newImpl = static_cast<Impl*>(realloc(mImpl, size * sizeof(void*)));
NS_ENSURE_TRUE(newImpl, false);

mImpl = newImpl;
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6052,7 +6052,7 @@ nsContentUtils::CreateBlobBuffer(JSContext* aCx,
JS::MutableHandle<JS::Value> aBlob)
{
uint32_t blobLen = aData.Length();
void* blobData = moz_malloc(blobLen);
void* blobData = malloc(blobLen);
nsRefPtr<File> blob;
if (blobData) {
memcpy(blobData, aData.BeginReading(), blobLen);
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsDOMFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)
return NS_ERROR_OUT_OF_MEMORY;
}
if (mDataFormat != FILE_AS_ARRAYBUFFER) {
mFileData = (char *) moz_realloc(mFileData, mDataLen + aCount);
mFileData = (char *) realloc(mFileData, mDataLen + aCount);
NS_ENSURE_TRUE(mFileData, NS_ERROR_OUT_OF_MEMORY);
}

Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsDOMFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class nsDOMFileReader final : public mozilla::dom::FileIOObject,
nsresult GetAsDataURL(nsIDOMBlob *aFile, const char *aFileData, uint32_t aDataLen, nsAString &aResult);

void FreeFileData() {
moz_free(mFileData);
free(mFileData);
mFileData = nullptr;
mDataLen = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
}
rv = NS_OK;
} else {
moz_free(const_cast<uint8_t *>(aString));
free(const_cast<uint8_t *>(aString));
rv = NS_SUCCESS_ADOPTED_DATA;
}

Expand Down
22 changes: 11 additions & 11 deletions dom/base/nsTextFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void
nsTextFragment::ReleaseText()
{
if (mState.mLength && m1b && mState.mInHeap) {
moz_free(m2b); // m1b == m2b as far as moz_free is concerned
free(m2b); // m1b == m2b as far as free is concerned
}

m1b = nullptr;
Expand All @@ -107,7 +107,7 @@ nsTextFragment::operator=(const nsTextFragment& aOther)
size_t m2bSize = aOther.mState.mLength *
(aOther.mState.mIs2b ? sizeof(char16_t) : sizeof(char));

m2b = static_cast<char16_t*>(moz_malloc(m2bSize));
m2b = static_cast<char16_t*>(malloc(m2bSize));
if (m2b) {
memcpy(m2b, aOther.m2b, m2bSize);
} else {
Expand Down Expand Up @@ -255,7 +255,7 @@ nsTextFragment::SetTo(const char16_t* aBuffer, int32_t aLength, bool aUpdateBidi
if (first16bit != -1) { // aBuffer contains no non-8bit character
// Use ucs2 storage because we have to
size_t m2bSize = aLength * sizeof(char16_t);
m2b = (char16_t *)moz_malloc(m2bSize);
m2b = (char16_t *)malloc(m2bSize);
if (!m2b) {
return false;
}
Expand All @@ -268,7 +268,7 @@ nsTextFragment::SetTo(const char16_t* aBuffer, int32_t aLength, bool aUpdateBidi

} else {
// Use 1 byte storage because we can
char* buff = (char *)moz_malloc(aLength * sizeof(char));
char* buff = (char *)malloc(aLength * sizeof(char));
if (!buff) {
return false;
}
Expand Down Expand Up @@ -326,7 +326,7 @@ nsTextFragment::Append(const char16_t* aBuffer, uint32_t aLength, bool aUpdateBi

if (mState.mIs2b) {
// Already a 2-byte string so the result will be too
char16_t* buff = (char16_t*)moz_realloc(m2b, (mState.mLength + aLength) * sizeof(char16_t));
char16_t* buff = (char16_t*)realloc(m2b, (mState.mLength + aLength) * sizeof(char16_t));
if (!buff) {
return false;
}
Expand All @@ -348,8 +348,8 @@ nsTextFragment::Append(const char16_t* aBuffer, uint32_t aLength, bool aUpdateBi
if (first16bit != -1) { // aBuffer contains no non-8bit character
// The old data was 1-byte, but the new is not so we have to expand it
// all to 2-byte
char16_t* buff = (char16_t*)moz_malloc((mState.mLength + aLength) *
sizeof(char16_t));
char16_t* buff =
(char16_t*)malloc((mState.mLength + aLength) * sizeof(char16_t));
if (!buff) {
return false;
}
Expand All @@ -363,7 +363,7 @@ nsTextFragment::Append(const char16_t* aBuffer, uint32_t aLength, bool aUpdateBi
mState.mIs2b = true;

if (mState.mInHeap) {
moz_free(m2b);
free(m2b);
}
m2b = buff;

Expand All @@ -379,14 +379,14 @@ nsTextFragment::Append(const char16_t* aBuffer, uint32_t aLength, bool aUpdateBi
// The new and the old data is all 1-byte
char* buff;
if (mState.mInHeap) {
buff = (char*)moz_realloc(const_cast<char*>(m1b),
(mState.mLength + aLength) * sizeof(char));
buff = (char*)realloc(const_cast<char*>(m1b),
(mState.mLength + aLength) * sizeof(char));
if (!buff) {
return false;
}
}
else {
buff = (char*)moz_malloc((mState.mLength + aLength) * sizeof(char));
buff = (char*)malloc((mState.mLength + aLength) * sizeof(char));
if (!buff) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/canvas/WebGLContextBuffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ WebGLContext::BufferData(GLenum target, WebGLsizeiptr size, GLenum usage)
if (!boundBuffer)
return ErrorInvalidOperation("bufferData: no buffer bound!");

UniquePtr<uint8_t> zeroBuffer((uint8_t*)moz_calloc(size, 1));
UniquePtr<uint8_t> zeroBuffer((uint8_t*)calloc(size, 1));
if (!zeroBuffer)
return ErrorOutOfMemory("bufferData: out of memory");

Expand Down
2 changes: 1 addition & 1 deletion dom/fetch/Fetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ class MOZ_STACK_CLASS AutoFreeBuffer final {

~AutoFreeBuffer()
{
moz_free(mBuffer);
free(mBuffer);
}

void
Expand Down
8 changes: 4 additions & 4 deletions dom/indexedDB/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14785,14 +14785,14 @@ ObjectStoreAddOrPutRequestOp::DoDatabaseWork(TransactionBase* aTransaction)
reinterpret_cast<const char*>(mParams.cloneInfo().data().Elements());
size_t uncompressedLength = mParams.cloneInfo().data().Length();

// We don't have a smart pointer class that calls moz_free, so we need to
// We don't have a smart pointer class that calls free, so we need to
// manage | compressed | manually.
{
size_t compressedLength = snappy::MaxCompressedLength(uncompressedLength);

// moz_malloc is equivalent to NS_Alloc, which we use because mozStorage
// malloc is equivalent to NS_Alloc, which we use because mozStorage
// expects to be able to free the adopted pointer with NS_Free.
char* compressed = static_cast<char*>(moz_malloc(compressedLength));
char* compressed = static_cast<char*>(malloc(compressedLength));
if (NS_WARN_IF(!compressed)) {
return NS_ERROR_OUT_OF_MEMORY;
}
Expand All @@ -14808,7 +14808,7 @@ ObjectStoreAddOrPutRequestOp::DoDatabaseWork(TransactionBase* aTransaction)
rv = stmt->BindAdoptedBlobByName(NS_LITERAL_CSTRING("data"), dataBuffer,
dataBufferLength);
if (NS_WARN_IF(NS_FAILED(rv))) {
moz_free(compressed);
free(compressed);
return rv;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/Blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ CreateBlobImpl(const nsTArray<uint8_t>& aMemoryData,
return nullptr;
}

void* buffer = moz_malloc(length * elementSizeMultiplier);
void* buffer = malloc(length * elementSizeMultiplier);
if (NS_WARN_IF(!buffer)) {
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/media/EncodedBufferCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ EncodedBufferCache::ExtractBlob(nsISupports* aParent,
mDataSize = 0;
mFD = nullptr;
} else {
void* blobData = moz_malloc(mDataSize);
void* blobData = malloc(mDataSize);
NS_ASSERTION(blobData, "out of memory!!");

if (blobData) {
Expand Down
4 changes: 2 additions & 2 deletions dom/media/webaudio/AnalyserNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ AnalyserNode::FFTAnalysis()
if (mWriteIndex == 0) {
inputBuffer = mBuffer.Elements();
} else {
inputBuffer = static_cast<float*>(moz_malloc(FftSize() * sizeof(float)));
inputBuffer = static_cast<float*>(malloc(FftSize() * sizeof(float)));
if (!inputBuffer) {
return false;
}
Expand All @@ -280,7 +280,7 @@ AnalyserNode::FFTAnalysis()
}

if (allocated) {
moz_free(inputBuffer);
free(inputBuffer);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/media/webrtc/AudioOutputObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AudioOutputObserver : public MixerCallbackReceiver
uint32_t mChunkSize;

// chunking to 10ms support
FarEndAudioChunk *mSaved; // can't be nsAutoPtr since we need to use moz_free()
FarEndAudioChunk *mSaved; // can't be nsAutoPtr since we need to use free(), not delete
uint32_t mSamplesSaved;
};

Expand Down
2 changes: 1 addition & 1 deletion dom/media/webrtc/MediaEngineGonkVideoSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ MediaEngineGonkVideoSource::OnTakePictureComplete(uint8_t* aData, uint32_t aLeng
: mPhotoDataLength(aLength)
{
mCallbacks.SwapElements(aCallbacks);
mPhotoData = (uint8_t*) moz_malloc(aLength);
mPhotoData = (uint8_t*) malloc(aLength);
memcpy(mPhotoData, aData, mPhotoDataLength);
mMimeType = aMimeType;
}
Expand Down
8 changes: 4 additions & 4 deletions dom/media/webrtc/MediaEngineWebRTCAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ AudioOutputObserver::AudioOutputObserver()
AudioOutputObserver::~AudioOutputObserver()
{
Clear();
moz_free(mSaved);
free(mSaved);
mSaved = nullptr;
}

void
AudioOutputObserver::Clear()
{
while (mPlayoutFifo->size() > 0) {
moz_free(mPlayoutFifo->Pop());
free(mPlayoutFifo->Pop());
}
// we'd like to touch mSaved here, but we can't if we might still be getting callbacks
}
Expand Down Expand Up @@ -544,7 +544,7 @@ MediaEngineWebRTCAudioSource::Process(int channel,
if (!mStarted) {
mStarted = true;
while (gFarendObserver->Size() > 1) {
moz_free(gFarendObserver->Pop()); // only call if size() > 0
free(gFarendObserver->Pop()); // only call if size() > 0
}
}

Expand All @@ -557,7 +557,7 @@ MediaEngineWebRTCAudioSource::Process(int channel,
gFarendObserver->PlayoutChannels(),
mPlayoutDelay,
length);
moz_free(buffer);
free(buffer);
if (res == -1) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions dom/plugins/ipc/PluginInterposeOSX.mm
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@
}
}

moz_free(bitmap);
free(bitmap);
}

NSCursorInfo::~NSCursorInfo()
{
if (mCustomImageData) {
moz_free(mCustomImageData);
free(mCustomImageData);
}
}

Expand Down Expand Up @@ -438,7 +438,7 @@
}
}

moz_free(data);
free(data);

// Fall back to an arrow cursor if (for some reason) the above code failed.
if (!retval) {
Expand Down Expand Up @@ -528,7 +528,7 @@
void NSCursorInfo::SetCustomImageData(uint8_t* aData, uint32_t aDataLength)
{
if (mCustomImageData) {
moz_free(mCustomImageData);
free(mCustomImageData);
}
if (aDataLength) {
mCustomImageData = (uint8_t*) moz_xmalloc(aDataLength);
Expand Down
6 changes: 3 additions & 3 deletions dom/xul/nsXULContentSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ XULContentSinkImpl::~XULContentSinkImpl()
NS_ASSERTION(mContextStack.Depth() == 0, "Context stack not empty?");
mContextStack.Clear();

moz_free(mText);
free(mText);
}

//----------------------------------------------------------------------
Expand Down Expand Up @@ -1051,7 +1051,7 @@ XULContentSinkImpl::AddText(const char16_t* aText,
{
// Create buffer when we first need it
if (0 == mTextSize) {
mText = (char16_t *) moz_malloc(sizeof(char16_t) * 4096);
mText = (char16_t *) malloc(sizeof(char16_t) * 4096);
if (nullptr == mText) {
return NS_ERROR_OUT_OF_MEMORY;
}
Expand All @@ -1074,7 +1074,7 @@ XULContentSinkImpl::AddText(const char16_t* aText,
}
else {
mTextSize += aLength;
mText = (char16_t *) moz_realloc(mText, sizeof(char16_t) * mTextSize);
mText = (char16_t *) realloc(mText, sizeof(char16_t) * mTextSize);
if (nullptr == mText) {
return NS_ERROR_OUT_OF_MEMORY;
}
Expand Down
Loading

0 comments on commit 20130cf

Please sign in to comment.