fornaxM / mpoauthconnection

Automatically exported from code.google.com/p/mpoauthconnection
0 stars 0 forks source link

Crash handling notification in MPOAuthAuthenticationMethodOAuth #36

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Second instance of MPOauthAPI using OAuth authentication method crashes the 
application when recieving the request token (if the first instance was 
deallocated). There are two reasons for this:

1) In the MPOAuthAPI initializer 
-initWithCredentials:authenticationURL:andBaseURL:autoStart:
an authentication method instance is created on line 58 (r130) and assigned to 
authenticationMethod property like so: 

  self.authenticationMethod = [[MPOAuthAuthenticationMethod alloc] initWithAPI:self forURL:inAuthURL];                            

this results in a retainCount value of 2 (1 for init, one for 
@property(retain)) so when the MPOAuthAPI instance is deallocated, the 
authenticationMethod is never released and leaks. 

2) MPOAuthAuthenticationMethodOAuth registers itself as an observer for 
MPOAuthNotificationRequestTokenReceived notification and never removes itself 
when deallocating. So when another MPOAuthAPI instance with it's own 
authentication method posts the notification, the original instance receives it 
as well. 

This gets further obscured by the fact, that the first instance of 
MPOAuthAuthenticationMethodOAuth is still alive because of the leak in 1). 

These two changes fix the issue:

1) MPOAuthAPI.m:58(r130) change to:
authenticationMethod_ = [[MPOAuthAuthenticationMethod alloc] initWithAPI:self 
forURL:inAuthURL];              

2) MPOAuthAuthenticationMethodOAuth:62(r130) in -dealloc add the following:
[[NSNotificationCenter defaultCenter] removeObserver:self];

Original issue reported on code.google.com by chary...@gmail.com on 16 Aug 2010 at 12:16

GoogleCodeExporter commented 9 years ago
Thanks for catching these issues. I've gone ahead and made the changes, but 
have to wait to submit since for whatever reason google code is currently 
returning temporarily unavailable for all operations. So I'll try again later.

Original comment by karl.a...@gmail.com on 16 Aug 2010 at 12:39