DNESS / cocos2d-iphone

Automatically exported from code.google.com/p/cocos2d-iphone
1 stars 0 forks source link

Memory leak in CCGLProgram.m #1494

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
This is a testcase for causing the leak:

CCGLProgram* program;
for(int i= 1; i<100; ++i) {
    program = [CCGLProgram programWithVertexShaderFilename:@"test" fragmentShaderFilename:@"test"];
}

Notice both vertexShaderFilename and fragmentShaderFilename are invalid but 
non-nil.

Problem:
CCGLProgram.m line 130
- (id)initWithVertexShaderFilename:(NSString *)vShaderFilename 
fragmentShaderFilename:(NSString *)fShaderFilename
returns nil in this case.

The leak occurs on line 81:
return [[[self alloc] initWithVertexShaderFilename:vShaderFilename 
fragmentShaderFilename:fShaderFilename] autorelease];

autorelease is called on nil, not on self.

Suggested solution:
in CCGLProgram.m, insert
[self release];
right before returning nil on line 130.

What is the expected output? What do you see instead?
The method should return nil without a leak.

What cocos2d version are you using ?
cocos2d-iphone-2.1-rc1

What iOS / Mac SDK are you using ?
iOS 6.1

Debug or Release ?
Debug

Which target device / target OS are you using ?

iOS only: Does this happens on device ? or on the simulator ? or on both ?
both

Original issue reported on code.google.com by pounciva...@yahoo.de on 13 Jun 2013 at 12:14