Fixed bug #1027
authorSam Lantinga <slouken@libsdl.org>
Wed, 19 Jan 2011 23:45:29 -0800
changeset 5051a69e36365766
parent 5050 2add0d17180b
child 5052 4cb4b18cbae3
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
     1.1 --- a/src/video/uikit/SDL_uikitview.m	Wed Jan 19 22:55:51 2011 -0800
     1.2 +++ b/src/video/uikit/SDL_uikitview.m	Wed Jan 19 23:45:29 2011 -0800
     1.3 @@ -35,9 +35,6 @@
     1.4  @implementation SDL_uikitview
     1.5  
     1.6  - (void)dealloc {
     1.7 -#if SDL_IPHONE_KEYBOARD
     1.8 -	[textField release];
     1.9 -#endif
    1.10  	[super dealloc];
    1.11  }
    1.12  
    1.13 @@ -220,7 +217,7 @@
    1.14  /* Set ourselves up as a UITextFieldDelegate */
    1.15  - (void)initializeKeyboard {
    1.16  		
    1.17 -	textField = [[[UITextField alloc] initWithFrame: CGRectZero] autorelease];
    1.18 +	textField = [[UITextField alloc] initWithFrame: CGRectZero];
    1.19  	textField.delegate = self;
    1.20  	/* placeholder so there is something to delete! */
    1.21  	textField.text = @" ";	
    1.22 @@ -238,6 +235,7 @@
    1.23  	keyboardVisible = NO;
    1.24  	/* add the UITextField (hidden) to our view */
    1.25  	[self addSubview: textField];
    1.26 +	[textField release];
    1.27  }
    1.28  
    1.29  /* reveal onscreen virtual keyboard */