Bug 956630. Replace nsMemory::Alloc/nsMemory::Realloc calls with moz_malloc/moz_realloc to avoid application aborts and successfully check for not allocated memory. r=jduell
authorNick Lebedev <nicklebedev37@gmail.com>
Mon, 13 Jan 2014 21:53:00 -0800
changeset 181960 98d0a4876836c603b2ecee02cc67d8b3f63ce127
parent 181959 38c297cc1babe8eb379c706bf49be0585e12ec54
child 181961 e864fca8c73e674ef18930d61d53387c4094f7c5
push id462
push userraliiev@mozilla.com
push dateTue, 22 Apr 2014 00:22:30 +0000
treeherdermozilla-release@ac5db8c74ac0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell
bugs956630
milestone29.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 956630. Replace nsMemory::Alloc/nsMemory::Realloc calls with moz_malloc/moz_realloc to avoid application aborts and successfully check for not allocated memory. r=jduell
netwerk/streamconv/converters/nsBinHexDecoder.cpp
netwerk/streamconv/converters/nsHTTPCompressConv.cpp
netwerk/streamconv/converters/nsIndexedToHTML.cpp
--- a/netwerk/streamconv/converters/nsBinHexDecoder.cpp
+++ b/netwerk/streamconv/converters/nsBinHexDecoder.cpp
@@ -437,18 +437,18 @@ int16_t nsBinHexDecoder::GetNextChar(uin
 
 NS_IMETHODIMP
 nsBinHexDecoder::OnStartRequest(nsIRequest* request, nsISupports *aCtxt)
 {
   nsresult rv = NS_OK;
 
   NS_ENSURE_TRUE(mNextListener, NS_ERROR_FAILURE);
 
-  mDataBuffer = (char *) nsMemory::Alloc((sizeof(char) * nsIOService::gDefaultSegmentSize));
-  mOutgoingBuffer = (char *) nsMemory::Alloc((sizeof(char) * nsIOService::gDefaultSegmentSize));
+  mDataBuffer = (char *) moz_malloc((sizeof(char) * nsIOService::gDefaultSegmentSize));
+  mOutgoingBuffer = (char *) moz_malloc((sizeof(char) * nsIOService::gDefaultSegmentSize));
   if (!mDataBuffer || !mOutgoingBuffer) return NS_ERROR_FAILURE; // out of memory;
 
   // now we want to create a pipe which we'll use to write our converted data...
   rv = NS_NewPipe(getter_AddRefs(mInputStream), getter_AddRefs(mOutputStream),
                   nsIOService::gDefaultSegmentSize,
                   nsIOService::gDefaultSegmentSize,
                   true, true);
 
--- a/netwerk/streamconv/converters/nsHTTPCompressConv.cpp
+++ b/netwerk/streamconv/converters/nsHTTPCompressConv.cpp
@@ -128,30 +128,30 @@ nsHTTPCompressConv::OnDataAvailable(nsIR
                 return NS_OK;
 
             // FALLTHROUGH
 
         case HTTP_COMPRESS_DEFLATE:
 
             if (mInpBuffer != nullptr && streamLen > mInpBufferLen)
             {
-                mInpBuffer = (unsigned char *) nsMemory::Realloc(mInpBuffer, mInpBufferLen = streamLen);
+                mInpBuffer = (unsigned char *) moz_realloc(mInpBuffer, mInpBufferLen = streamLen);
                
                 if (mOutBufferLen < streamLen * 2)
-                    mOutBuffer = (unsigned char *) nsMemory::Realloc(mOutBuffer, mOutBufferLen = streamLen * 3);
+                    mOutBuffer = (unsigned char *) moz_realloc(mOutBuffer, mOutBufferLen = streamLen * 3);
 
                 if (mInpBuffer == nullptr || mOutBuffer == nullptr)
                     return NS_ERROR_OUT_OF_MEMORY;
             }
 
             if (mInpBuffer == nullptr)
-                mInpBuffer = (unsigned char *) nsMemory::Alloc(mInpBufferLen = streamLen);
+                mInpBuffer = (unsigned char *) moz_malloc(mInpBufferLen = streamLen);
 
             if (mOutBuffer == nullptr)
-                mOutBuffer = (unsigned char *) nsMemory::Alloc(mOutBufferLen = streamLen * 3);
+                mOutBuffer = (unsigned char *) moz_malloc(mOutBufferLen = streamLen * 3);
 
             if (mInpBuffer == nullptr || mOutBuffer == nullptr)
                 return NS_ERROR_OUT_OF_MEMORY;
 
             uint32_t unused;
             iStr->Read((char *)mInpBuffer, streamLen, &unused);
 
             if (mMode == HTTP_COMPRESS_DEFLATE)
--- a/netwerk/streamconv/converters/nsIndexedToHTML.cpp
+++ b/netwerk/streamconv/converters/nsIndexedToHTML.cpp
@@ -705,17 +705,17 @@ nsIndexedToHTML::FormatInputStream(nsIRe
     // convert the data with unicode encoder
     char *buffer = nullptr;
     int32_t dstLength;
     if (NS_SUCCEEDED(rv)) {
       int32_t unicharLength = aBuffer.Length();
       rv = mUnicodeEncoder->GetMaxLength(PromiseFlatString(aBuffer).get(), 
                                          unicharLength, &dstLength);
       if (NS_SUCCEEDED(rv)) {
-        buffer = (char *) nsMemory::Alloc(dstLength);
+        buffer = (char *) moz_malloc(dstLength);
         NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
 
         rv = mUnicodeEncoder->Convert(PromiseFlatString(aBuffer).get(), &unicharLength, 
                                       buffer, &dstLength);
         if (NS_SUCCEEDED(rv)) {
           int32_t finLen = 0;
           rv = mUnicodeEncoder->Finish(buffer + dstLength, &finLen);
           if (NS_SUCCEEDED(rv))