зеркало из https://github.com/mozilla/gecko-dev.git
Bug 514033 - Error recovery for imagelib - part 16 - Eliminate checks for infallible malloc, use infallible malloc when we need it.r=joe,a=blocker
This commit is contained in:
Родитель
ef5de07886
Коммит
40ae4c2141
|
@ -70,7 +70,6 @@ typedef enum {
|
|||
gif_consume_block,
|
||||
gif_skip_block,
|
||||
gif_done,
|
||||
gif_oom,
|
||||
gif_error,
|
||||
gif_comment_extension,
|
||||
gif_application_extension,
|
||||
|
|
|
@ -212,11 +212,6 @@ nsBMPDecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
|
|||
|
||||
// Always allocate 256 even though mNumColors might be smaller
|
||||
mColors = new colorTable[256];
|
||||
if (!mColors) {
|
||||
PostDecoderError(NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(mColors, 0, 256 * sizeof(colorTable));
|
||||
}
|
||||
else if (mBIH.compression != BI_BITFIELDS && mBIH.bpp == 16) {
|
||||
|
@ -233,7 +228,7 @@ nsBMPDecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
|
|||
(PRUint8**)&mImageData, &imageLength);
|
||||
} else {
|
||||
// mRow is not used for RLE encoded images
|
||||
mRow = (PRUint8*)malloc((mBIH.width * mBIH.bpp)/8 + 4);
|
||||
mRow = (PRUint8*)moz_malloc((mBIH.width * mBIH.bpp)/8 + 4);
|
||||
// +4 because the line is padded to a 4 bit boundary, but I don't want
|
||||
// to make exact calculations here, that's unnecessary.
|
||||
// Also, it compensates rounding error.
|
||||
|
|
|
@ -977,11 +977,7 @@ nsGIFDecoder2::WriteInternal(const char *aBuffer, PRUint32 aCount)
|
|||
// as the image frame doesn't have its own palette
|
||||
mColormapSize = sizeof(PRUint32) << realDepth;
|
||||
if (!mGIFStruct.local_colormap) {
|
||||
mGIFStruct.local_colormap = (PRUint32*)PR_MALLOC(mColormapSize);
|
||||
if (!mGIFStruct.local_colormap) {
|
||||
mGIFStruct.state = gif_oom;
|
||||
break;
|
||||
}
|
||||
mGIFStruct.local_colormap = (PRUint32*)moz_xmalloc(mColormapSize);
|
||||
}
|
||||
mColormap = mGIFStruct.local_colormap;
|
||||
}
|
||||
|
@ -1058,11 +1054,6 @@ nsGIFDecoder2::WriteInternal(const char *aBuffer, PRUint32 aCount)
|
|||
PostDataError();
|
||||
return;
|
||||
|
||||
// Handle out of memory errors
|
||||
case gif_oom:
|
||||
PostDecoderError(NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
|
||||
// We shouldn't ever get here.
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -235,10 +235,6 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
|
|||
}
|
||||
|
||||
mColors = new colorTable[mNumColors];
|
||||
if (!mColors) {
|
||||
PostDecoderError(NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mIsCursor) {
|
||||
|
@ -255,7 +251,7 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
|
|||
}
|
||||
|
||||
mCurLine = mDirEntry.mHeight;
|
||||
mRow = (PRUint8*)malloc((mDirEntry.mWidth * mBIH.bpp)/8 + 4);
|
||||
mRow = (PRUint8*)moz_malloc((mDirEntry.mWidth * mBIH.bpp)/8 + 4);
|
||||
// +4 because the line is padded to a 4 bit boundary, but I don't want
|
||||
// to make exact calculations here, that's unnecessary.
|
||||
// Also, it compensates rounding error.
|
||||
|
|
|
@ -238,11 +238,7 @@ nsPNGDecoder::InitInternal()
|
|||
|
||||
// For size decodes, we only need a small buffer
|
||||
if (IsSizeDecode()) {
|
||||
mHeaderBuf = (PRUint8 *)nsMemory::Alloc(BYTES_NEEDED_FOR_DIMENSIONS);
|
||||
if (!mHeaderBuf) {
|
||||
PostDecoderError(NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
}
|
||||
mHeaderBuf = (PRUint8 *)moz_xmalloc(BYTES_NEEDED_FOR_DIMENSIONS);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -624,7 +620,7 @@ nsPNGDecoder::info_callback(png_structp png_ptr, png_infop info_ptr)
|
|||
(channels <= 2 || interlace_type == PNG_INTERLACE_ADAM7)) {
|
||||
PRUint32 bpp[] = { 0, 3, 4, 3, 4 };
|
||||
decoder->mCMSLine =
|
||||
(PRUint8 *)nsMemory::Alloc(bpp[channels] * width);
|
||||
(PRUint8 *)moz_malloc(bpp[channels] * width);
|
||||
if (!decoder->mCMSLine) {
|
||||
longjmp(png_jmpbuf(decoder->mPNG), 5); // NS_ERROR_OUT_OF_MEMORY
|
||||
}
|
||||
|
@ -632,8 +628,7 @@ nsPNGDecoder::info_callback(png_structp png_ptr, png_infop info_ptr)
|
|||
|
||||
if (interlace_type == PNG_INTERLACE_ADAM7) {
|
||||
if (height < PR_INT32_MAX / (width * channels))
|
||||
decoder->interlacebuf = (PRUint8 *)nsMemory::Alloc(channels *
|
||||
width * height);
|
||||
decoder->interlacebuf = (PRUint8 *)moz_malloc(channels * width * height);
|
||||
if (!decoder->interlacebuf) {
|
||||
longjmp(png_jmpbuf(decoder->mPNG), 5); // NS_ERROR_OUT_OF_MEMORY
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче