Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fixed bug 1641 - avoid allocating nsstring from char*

Vittorio Giovara 2012-11-12 05:52:47 PST

Changesets 4f272256d172 and 42214b6959c5 introduce two neat features for
logging and alertbox on ios and osx.
However the NSString allocated (and a few other objects) are not freed by the
autorelease pool when created by +alloc and -initWithStuff: and this will
create leaks. While negligible on osx, on mobile it's better not to have leaks.
Attached is a patch that should take care of the problems on both platforms.
  • Loading branch information
slouken committed Nov 29, 2012
1 parent 4a744e7 commit 7020b3fdc9adaeeb7f5083058109d41bb1fdfdfa
@@ -51,8 +51,8 @@
[alert setAlertStyle:NSInformationalAlertStyle];
}

[alert setMessageText:[[NSString alloc] initWithUTF8String:messageboxdata->title]];
[alert setInformativeText:[[NSString alloc] initWithUTF8String:messageboxdata->message]];
[alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
[alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];

const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
int i;
@@ -70,6 +70,7 @@
NSInteger clicked = [alert runModal];
clicked -= NSAlertFirstButtonReturn;
*buttonid = buttons[clicked].buttonid;
[alert release];

[pool release];

@@ -228,11 +228,7 @@

void SDL_NSLog(const char *text)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSLog(@"%@", [[NSString alloc] initWithUTF8String:text]);

[pool release];
NSLog(@"%s", text);
}

/*
@@ -76,8 +76,8 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)

UIAlertView* alert = [[UIAlertView alloc] init];

alert.title = [[NSString alloc] initWithUTF8String:messageboxdata->title];
alert.message = [[NSString alloc] initWithUTF8String:messageboxdata->message];
alert.title = [NSString stringWithUTF8String:messageboxdata->title];
alert.message = [NSString stringWithUTF8String:messageboxdata->message];
alert.delegate = [[UIKit_UIAlertViewDelegate alloc] initWithButtonIndex:&clicked];

const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
@@ -100,6 +100,9 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)
s_showingMessageBox = SDL_FALSE;

*buttonid = messageboxdata->buttons[clicked].buttonid;

[alert.delegate release];
[alert release];

[pool release];

@@ -137,11 +137,7 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)

void SDL_NSLog(const char *text)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSLog(@"%@", [[NSString alloc] initWithUTF8String:text]);

[pool release];
NSLog(@"%s", text);
}

#endif /* SDL_VIDEO_DRIVER_UIKIT */

0 comments on commit 7020b3f

Please sign in to comment.