Merge pull request #5376 from dumganhar/free-new-mistake

new[] free mismatching after PR #5326.
This commit is contained in:
James Chen 2014-02-18 11:40:40 +08:00
commit 1428cea4df
7 changed files with 40 additions and 45 deletions

View File

@ -1 +1 @@
5bde2def1fece71a2464526c90939b9999ed05f3
a7af0ccd05e86210026f7c72d6f5a7be8e17fe3d

View File

@ -753,7 +753,7 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format)
if (outTempData != nullptr && outTempData != tempData)
{
delete [] outTempData;
free(outTempData);
}
// set the premultiplied tag
@ -781,32 +781,32 @@ Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, s
{
case PixelFormat::RGBA8888:
*outDataLen = dataLen*4;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertI8ToRGBA8888(data, dataLen, *outData);
break;
case PixelFormat::RGB888:
*outDataLen = dataLen*3;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertI8ToRGB888(data, dataLen, *outData);
break;
case PixelFormat::RGB565:
*outDataLen = dataLen*2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertI8ToRGB565(data, dataLen, *outData);
break;
case PixelFormat::AI88:
*outDataLen = dataLen*2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertI8ToAI88(data, dataLen, *outData);
break;
case PixelFormat::RGBA4444:
*outDataLen = dataLen*2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertI8ToRGBA4444(data, dataLen, *outData);
break;
case PixelFormat::RGB5A1:
*outDataLen = dataLen*2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertI8ToRGB5A1(data, dataLen, *outData);
break;
default:
@ -830,37 +830,37 @@ Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data,
{
case PixelFormat::RGBA8888:
*outDataLen = dataLen*2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertAI88ToRGBA8888(data, dataLen, *outData);
break;
case PixelFormat::RGB888:
*outDataLen = dataLen/2*3;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertAI88ToRGB888(data, dataLen, *outData);
break;
case PixelFormat::RGB565:
*outDataLen = dataLen;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertAI88ToRGB565(data, dataLen, *outData);
break;
case PixelFormat::A8:
*outDataLen = dataLen/2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertAI88ToA8(data, dataLen, *outData);
break;
case PixelFormat::I8:
*outDataLen = dataLen/2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertAI88ToI8(data, dataLen, *outData);
break;
case PixelFormat::RGBA4444:
*outDataLen = dataLen;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertAI88ToRGBA4444(data, dataLen, *outData);
break;
case PixelFormat::RGB5A1:
*outDataLen = dataLen;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertAI88ToRGB5A1(data, dataLen, *outData);
break;
default:
@ -885,32 +885,32 @@ Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* dat
{
case PixelFormat::RGBA8888:
*outDataLen = dataLen/3*4;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGB888ToRGBA8888(data, dataLen, *outData);
break;
case PixelFormat::RGB565:
*outDataLen = dataLen/3*2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGB888ToRGB565(data, dataLen, *outData);
break;
case PixelFormat::I8:
*outDataLen = dataLen/3;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGB888ToI8(data, dataLen, *outData);
break;
case PixelFormat::AI88:
*outDataLen = dataLen/3*2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGB888ToAI88(data, dataLen, *outData);
break;
case PixelFormat::RGBA4444:
*outDataLen = dataLen/3*2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGB888ToRGBA4444(data, dataLen, *outData);
break;
case PixelFormat::RGB5A1:
*outDataLen = dataLen;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGB888ToRGB5A1(data, dataLen, *outData);
break;
default:
@ -934,37 +934,37 @@ Texture2D::PixelFormat Texture2D::convertRGBA8888ToFormat(const unsigned char* d
{
case PixelFormat::RGB888:
*outDataLen = dataLen/4*3;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGBA8888ToRGB888(data, dataLen, *outData);
break;
case PixelFormat::RGB565:
*outDataLen = dataLen/2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGBA8888ToRGB565(data, dataLen, *outData);
break;
case PixelFormat::A8:
*outDataLen = dataLen/4;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGBA8888ToA8(data, dataLen, *outData);
break;
case PixelFormat::I8:
*outDataLen = dataLen/4;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGBA8888ToI8(data, dataLen, *outData);
break;
case PixelFormat::AI88:
*outDataLen = dataLen/2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGBA8888ToAI88(data, dataLen, *outData);
break;
case PixelFormat::RGBA4444:
*outDataLen = dataLen/2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGBA8888ToRGBA4444(data, dataLen, *outData);
break;
case PixelFormat::RGB5A1:
*outDataLen = dataLen/2;
*outData = new unsigned char[*outDataLen];
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
convertRGBA8888ToRGB5A1(data, dataLen, *outData);
break;
default:
@ -1094,7 +1094,7 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin
if (outTempData != nullptr && outTempData != outData.getBytes())
{
delete [] outTempData;
free(outTempData);
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
_hasPremultipliedAlpha = true;

View File

@ -78,10 +78,6 @@ public:
~BitmapDC(void)
{
if (_data)
{
delete [] _data;
}
}
bool getBitmapFromJavaShadowStroke( const char *text,
@ -115,11 +111,11 @@ public:
// Do a full lookup for the font path using FileUtils in case the given font name is a relative path to a font file asset,
// or the path has been mapped to a different location in the app package:
std::string fullPathOrFontName = FileUtils::getInstance()->fullPathForFilename(pFontName);
// If the path name returned includes the 'assets' dir then that needs to be removed, because the android.content.Context
// requires this portion of the path to be omitted for assets inside the app package.
if (fullPathOrFontName.find("assets/") == 0)
{
// If the path name returned includes the 'assets' dir then that needs to be removed, because the android.content.Context
// requires this portion of the path to be omitted for assets inside the app package.
if (fullPathOrFontName.find("assets/") == 0)
{
fullPathOrFontName = fullPathOrFontName.substr(strlen("assets/")); // Chop out the 'assets/' portion of the path.
}
@ -163,7 +159,6 @@ public:
int _width;
int _height;
unsigned char *_data;
JNIEnv *env;
};
static BitmapDC& sharedBitmapDC()
@ -222,7 +217,7 @@ extern "C"
cocos2d::BitmapDC& bitmapDC = cocos2d::sharedBitmapDC();
bitmapDC._width = width;
bitmapDC._height = height;
bitmapDC._data = new unsigned char[size];
bitmapDC._data = (unsigned char*)malloc(sizeof(unsigned char) * size);
env->GetByteArrayRegion(pixels, 0, size, (jbyte*)bitmapDC._data);
}
};

View File

@ -326,7 +326,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align,
dim.height += shadowStrokePaddingY;
unsigned char* data = new unsigned char[(int)(dim.width * dim.height * 4)];
unsigned char* data = (unsigned char*)malloc(sizeof(unsigned char) * (int)(dim.width * dim.height * 4));
memset(data, 0, (int)(dim.width * dim.height * 4));
// draw text
@ -341,7 +341,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align,
if (!context)
{
CGColorSpaceRelease(colorSpace);
delete[] data;
CC_SAFE_FREE(data);
break;
}

View File

@ -411,7 +411,7 @@ public:
int txtHeight = iMaxLineHeight;
iMaxLineHeight = MAX(iMaxLineHeight, nHeight);
_data = new unsigned char[iMaxLineWidth * iMaxLineHeight * 4];
_data = (unsigned char*)malloc(sizeof(unsigned char) * (iMaxLineWidth * iMaxLineHeight * 4));
memset(_data,0, iMaxLineWidth * iMaxLineHeight*4);
int iCurYCursor = computeLineStartY(face, eAlignMask, txtHeight, iMaxLineHeight);

View File

@ -207,7 +207,7 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
NSUInteger textureSize = POTWide*POTHigh*4;
unsigned char* dataNew = new unsigned char[textureSize];
unsigned char* dataNew = (unsigned char*)malloc(sizeof(unsigned char) * textureSize);
if (dataNew) {
memcpy(dataNew, data, textureSize);
// output params

View File

@ -412,7 +412,7 @@ Data Device::getTextureDataForText(const char * text,const FontDefinition& textD
CC_BREAK_IF(! dc.drawText(text, size, align));
int dataLen = size.cx * size.cy * 4;
unsigned char* dataBuf = new unsigned char[dataLen];
unsigned char* dataBuf = (unsigned char*)malloc(sizeof(unsigned char) * dataLen);
CC_BREAK_IF(! dataBuf);
struct