From 6823704a46d7ec51ddc9919de65578f1a5ee5c74 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 10 Apr 2012 18:17:08 +0800 Subject: [PATCH] fixed #1138: Fixed a memory leak in CCTextureCache::addPVRImage. --- cocos2dx/textures/CCTextureCache.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 9037090a6e..979b81b907 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -457,7 +457,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path) { CCAssert(path != NULL, "TextureCache: fileimage MUST not be nill"); - CCTexture2D * tex; + CCTexture2D* tex = NULL; std::string key(path); // remove possible -HD suffix to prevent caching the same image twice (issue #1040) CCFileUtils::removeSuffixFromFile(key); @@ -470,7 +470,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path) // Split up directory and filename std::string fullpath = CCFileUtils::fullPathFromRelativePath(key.c_str()); tex = new CCTexture2D(); - if( tex->initWithPVRFile(fullpath.c_str()) ) + if(tex != NULL && tex->initWithPVRFile(fullpath.c_str()) ) { #if CC_ENABLE_CACHE_TEXTTURE_DATA // cache the texture file name @@ -482,6 +482,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path) else { CCLOG("cocos2d: Couldn't add PVRImage:%s in CCTextureCache",key.c_str()); + CC_SAFE_DELETE(tex); } return tex;