Plugged CoreFoundation memory leaks identified by Static Analyzer.

This commit is contained in:
Donald Alan Morrison 2012-08-24 23:34:20 -07:00
parent 9f1899978e
commit 857608495c
1 changed files with 10 additions and 9 deletions

View File

@ -235,7 +235,7 @@ static bool _initPremultipliedATextureWithImage(CGImageRef image, NSUInteger POT
CGContextRelease(context); CGContextRelease(context);
return true; return true;
} }
// TODO: rename _initWithImage, it also makes a draw call.
static bool _initWithImage(CGImageRef CGImage, tImageInfo *pImageinfo, double scaleX, double scaleY) static bool _initWithImage(CGImageRef CGImage, tImageInfo *pImageinfo, double scaleX, double scaleY)
{ {
NSUInteger POTWide, POTHigh; NSUInteger POTWide, POTHigh;
@ -258,10 +258,8 @@ static bool _initWithImage(CGImageRef CGImage, tImageInfo *pImageinfo, double sc
} }
// always load premultiplied images // load and draw image
_initPremultipliedATextureWithImage(CGImage, POTWide, POTHigh, pImageinfo); return _initPremultipliedATextureWithImage(CGImage, POTWide, POTHigh, pImageinfo);
return true;
} }
static bool _initWithFile(const char* path, tImageInfo *pImageinfo) static bool _initWithFile(const char* path, tImageInfo *pImageinfo)
@ -277,17 +275,19 @@ static bool _initWithFile(const char* path, tImageInfo *pImageinfo)
jpg = [[NSImage alloc] initWithContentsOfFile: fullPath]; jpg = [[NSImage alloc] initWithContentsOfFile: fullPath];
//png = [[NSImage alloc] initWithData:UIImagePNGRepresentation(jpg)]; //png = [[NSImage alloc] initWithData:UIImagePNGRepresentation(jpg)];
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)[jpg TIFFRepresentation], NULL); CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)[jpg TIFFRepresentation], NULL);
CGImage = CGImageSourceCreateImageAtIndex(source, 0, NULL); CGImage = CGImageSourceCreateImageAtIndex(source, 0, NULL);
ret = _initWithImage(CGImage, pImageinfo, 1.0, 1.0); ret = _initWithImage(CGImage, pImageinfo, 1.0, 1.0);
//[png release]; //[png release];
[jpg release]; [jpg release];
if (CGImage) CFRelease(CGImage);
if (source) CFRelease(source);
return ret; return ret;
} }
// TODO: rename _initWithData, it also makes a draw call.
static bool _initWithData(void * pBuffer, int length, tImageInfo *pImageinfo, double scaleX, double scaleY) static bool _initWithData(void * pBuffer, int length, tImageInfo *pImageinfo, double scaleX, double scaleY)
{ {
bool ret = false; bool ret = false;
@ -302,8 +302,9 @@ static bool _initWithData(void * pBuffer, int length, tImageInfo *pImageinfo, do
CGImage = CGImageSourceCreateImageAtIndex(source, 0, NULL); CGImage = CGImageSourceCreateImageAtIndex(source, 0, NULL);
ret = _initWithImage(CGImage, pImageinfo, scaleX, scaleY); ret = _initWithImage(CGImage, pImageinfo, scaleX, scaleY);
if (CGImage) CFRelease(CGImage);
if (source) CFRelease(source);
} }
return ret; return ret;
} }