CCTextureCache::addImage memory leak

unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(fullpath.c_str(), “rb”, &nSize);
CC_BREAK_IF(! image.initWithImageData((void**)pBuffer, nSize, eImageFormat));
CC_SAFE_DELETE_ARRAY;
should be:
unsigned char** pBuffer = CCFileUtils::sharedFileUtils()->getFileData(fullpath.c_str(), “rb”, &nSize);
if (! image.initWithImageData((void*)pBuffer, nSize, eImageFormat))
{
CC_SAFE_DELETE_ARRAY(pBuffer);
break;
}
CC_SAFE_DELETE_ARRAY(pBuffer);

@AlexanderMarkevich CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, eImageFormat)); only breaks when pBuffer0 or nSize0. So I guess the original code is ok. Not leaking

Alexander Markevich wrote:

unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(fullpath.c_str(), “rb”, &nSize);
CC_BREAK_IF(! image.initWithImageData((void**)pBuffer, nSize, eImageFormat));
CC_SAFE_DELETE_ARRAY;
>
should be:
>
unsigned char** pBuffer = CCFileUtils::sharedFileUtils()->getFileData(fullpath.c_str(), “rb”, &nSize);
if (! image.initWithImageData((void*)pBuffer, nSize, eImageFormat))
{
CC_SAFE_DELETE_ARRAY(pBuffer);
break;
}
CC_SAFE_DELETE_ARRAY(pBuffer);
i like your style.

Herman Jakobi wrote:

@AlexanderMarkevich CC_BREAK_IF(! image.initWithImageData((void**)pBuffer, nSize, eImageFormat)); only breaks when pBuffer0 or nSize0. So I guess the original code is ok. Not leaking

CCSprite**pTest = CCSprite::create(“”);
This is logic wrong creation, but after that we have a memory leak.

Alexander Markevich wrote:

CCSprite *pTest = CCSprite::create(“”);
This is logic wrong creation, but after that we have a memory leak.

Ok, but as you said…it’s just code that makes no sense. “” should trigger a Assert() anyway.

@Alexander Markevich, I’ve run the memory leak tool in instruments. There was no leak detected.
But you’re right, here’s a potential leak point. I fixed it at https://github.com/cocos2d/cocos2d-x/pull/1319

Walzer Wang wrote:

@Alexander Markevich, I’ve run the memory leak tool in instruments. There was no leak detected.
But you’re right, here’s a potential leak point. I fixed it at https://github.com/cocos2d/cocos2d-x/pull/1319

Thanks