OS X: Fix a few memory leaks.
This commit is contained in:
@@ -40,13 +40,13 @@ MenuHandle actions_menu,music_menu,mage_spells_menu,priest_spells_menu;
|
||||
|
||||
@interface MonsterWrapper : NSObject
|
||||
@property cMonster* monst;
|
||||
+(id) withMonster: (cMonster&) theMonster;
|
||||
+(id) withMonster: (cMonster&) theMonster NS_RETURNS_RETAINED;
|
||||
@end
|
||||
|
||||
@interface SpellWrapper : NSObject
|
||||
@property int num;
|
||||
@property eSkill type;
|
||||
+(id) withSpell:(int) num ofType:(eSkill) type;
|
||||
+(id) withSpell:(int) num ofType:(eSkill) type NS_RETURNS_RETAINED;
|
||||
@end
|
||||
|
||||
void hideMenuBar() {
|
||||
@@ -301,7 +301,7 @@ void menu_activate() {
|
||||
+(id) withMonster:(cMonster&) theMonster {
|
||||
MonsterWrapper* wrapper = [[MonsterWrapper alloc] init];
|
||||
[wrapper setMonst: &theMonster];
|
||||
return [wrapper retain];
|
||||
return wrapper;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -312,7 +312,7 @@ void menu_activate() {
|
||||
SpellWrapper* wrapper = [[SpellWrapper alloc] init];
|
||||
[wrapper setType: type];
|
||||
[wrapper setNum: num];
|
||||
return [wrapper retain];
|
||||
return wrapper;
|
||||
}
|
||||
@end
|
||||
|
||||
|
@@ -29,7 +29,7 @@ MenuHandle apple_menu, file_menu, reg_menu, extra_menu, items_menu[4];
|
||||
@end
|
||||
|
||||
@interface ItemWrapper : NSObject
|
||||
+(id) withItem:(int) theItem;
|
||||
+(id) withItem:(int) theItem NS_RETURNS_RETAINED;
|
||||
-(class cItem&) item;
|
||||
-(void) setItem:(int) theItem;
|
||||
@end
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include <string>
|
||||
#include "res_cursor.hpp"
|
||||
|
||||
static NSImage* imageFromURL(CFURLRef url) NS_RETURNS_RETAINED;
|
||||
static NSImage* imageFromURL(CFURLRef url){
|
||||
CGImageSourceRef imageSource = CGImageSourceCreateWithURL(url, nullptr);
|
||||
CGImageRef theImage = nil;
|
||||
@@ -18,7 +19,10 @@ static NSImage* imageFromURL(CFURLRef url){
|
||||
if(imageSource == nil) return nil;
|
||||
|
||||
theImage = CGImageSourceCreateImageAtIndex(imageSource, 0, nullptr);
|
||||
if(theImage == nil) return nil;
|
||||
if(theImage == nil) {
|
||||
CFRelease( imageSource );
|
||||
return nil;
|
||||
}
|
||||
|
||||
CFRelease( imageSource );
|
||||
|
||||
@@ -36,6 +40,7 @@ static NSImage* imageFromURL(CFURLRef url){
|
||||
CGContextRef imageContext = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
|
||||
CGContextDrawImage(imageContext, *(CGRect*)&imageRect, theImage);
|
||||
[newImage unlockFocus];
|
||||
CGImageRelease(theImage);
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
@@ -164,6 +164,8 @@ void set_clipboard_img(sf::Image& img) {
|
||||
NSImage * image = [[NSImage alloc] initWithSize: NSMakeSize(sz.x, sz.y)];
|
||||
[image addRepresentation: bmp];
|
||||
NSArray* contents = [NSArray arrayWithObject: image];
|
||||
[image release];
|
||||
[bmp release];
|
||||
NSPasteboard* pb = [NSPasteboard generalPasteboard];
|
||||
[pb clearContents];
|
||||
[pb writeObjects: contents];
|
||||
@@ -178,6 +180,7 @@ std::unique_ptr<sf::Image> get_clipboard_img() {
|
||||
return ret; // a null pointer
|
||||
NSImage* img = [[NSImage alloc] initWithPasteboard: pb];
|
||||
ret.reset(sfImageFromNSImage(img));
|
||||
[img release];
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -346,6 +349,7 @@ sf::Image* sfImageFromNSImage(NSImage *image) {
|
||||
|
||||
sf::Image* sfi = new sf::Image;
|
||||
sfi->create(width, height, (UInt8*) [rep bitmapData]);
|
||||
[rep release];
|
||||
|
||||
return sfi;
|
||||
}
|
||||
|
Reference in New Issue
Block a user