From 2d8a58a8992f168d68aa7422ef422617a4803098 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 19 Jan 2011 23:45:29 -0800 Subject: [PATCH] Fixed bug #1027 Vittorio Giovara 2010-07-17 19:21:36 PDT fix the double free error in SDL_uikitview the variable 'textfield' is initialialized and set to autorelease. however in the dealloc method a second [release] is sent. If the textfield has not been set to nil before (with a viewDidUnload for example) this can lead to awful hard-to-find crashes when the SDL code terminates. the error message is -[textfield release] message sent to deallocated instance 0x4e5fa90 the fix is simple, just release the object as soon as it is added to the subview, see attached patch --- src/video/uikit/SDL_uikitview.m | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index 74045359b..ff27b0fb9 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -35,9 +35,6 @@ @implementation SDL_uikitview - (void)dealloc { -#if SDL_IPHONE_KEYBOARD - [textField release]; -#endif [super dealloc]; } @@ -220,7 +217,7 @@ - (BOOL)keyboardVisible { /* Set ourselves up as a UITextFieldDelegate */ - (void)initializeKeyboard { - textField = [[[UITextField alloc] initWithFrame: CGRectZero] autorelease]; + textField = [[UITextField alloc] initWithFrame: CGRectZero]; textField.delegate = self; /* placeholder so there is something to delete! */ textField.text = @" "; @@ -238,6 +235,7 @@ - (void)initializeKeyboard { keyboardVisible = NO; /* add the UITextField (hidden) to our view */ [self addSubview: textField]; + [textField release]; } /* reveal onscreen virtual keyboard */