From 38b4e7ad2cff7e2714aba3bd029bc571644b5cbb Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Fri, 16 May 2014 11:02:23 -0700 Subject: [PATCH] fix memory leak for GLProgramState create logic --- cocos/renderer/CCGLProgramState.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cocos/renderer/CCGLProgramState.cpp b/cocos/renderer/CCGLProgramState.cpp index 6f7f05e88e..e0af0859b7 100644 --- a/cocos/renderer/CCGLProgramState.cpp +++ b/cocos/renderer/CCGLProgramState.cpp @@ -240,11 +240,14 @@ void VertexAttribValue::setPointer(GLint size, GLenum type, GLboolean normalized GLProgramState* GLProgramState::create(GLProgram *glprogram) { GLProgramState* ret = nullptr; - ret = new (std::nothrow) GLProgramState; - if(!ret || !ret->init(glprogram)) - CC_SAFE_RELEASE(ret); - - return ret; + ret = new (std::nothrow) GLProgramState(); + if(ret && ret->init(glprogram)) + { + ret->autorelease(); + return ret; + } + CC_SAFE_DELETE(ret); + return nullptr; } GLProgramState* GLProgramState::getOrCreateWithGLProgramName(const std::string &glProgramName )