Browse files

Fix a number of terrifying memory management errors.

  • Loading branch information...
1 parent 42c4283 commit 9b1db6c026a5de6b1bb30ce6469fd7b8cfa0b98b @adamjernst adamjernst committed Jun 22, 2011
Showing with 142 additions and 104 deletions.
  1. +1 −2 OAAttachment.m
  2. +8 −6 OACall.m
  3. +11 −4 OAConsumer.m
  4. +3 −2 OADataFetcher.m
  5. +2 −2 OAMutableURLRequest.h
  6. +33 −30 OAMutableURLRequest.m
  7. +7 −7 OAProblem.h
  8. +25 −18 OAProblem.m
  9. +11 −3 OARequestParameter.m
  10. +13 −5 OAServiceTicket.m
  11. +1 −1 OASignatureProviding.h
  12. +1 −1 OAToken.h
  13. +11 −9 OAToken.m
  14. +15 −14 OATokenManager.m
View
3 OAAttachment.m
@@ -13,8 +13,7 @@ @implementation OAAttachment
@synthesize name, fileName, contentType, data;
- (id)initWithName:(NSString *)aName filename:(NSString *)aFilename contentType:(NSString *)aContentType data:(NSData *)aData{
- self = [super init];
- if(self){
+ if((self = [super init])){
self.name = aName;
self.fileName = aFilename;
self.contentType = aContentType;
View
14 OACall.m
@@ -70,12 +70,14 @@ - (id)initWithURL:(NSURL *)aURL
method:(NSString *)aMethod
parameters:(NSArray *)theParameters
files:(NSDictionary*)theFiles {
- url = [aURL retain];
- method = [aMethod retain];
- parameters = [theParameters retain];
- files = [theFiles retain];
- fetcher = nil;
- request = nil;
+ if ((self = [super init])) {
+ url = [aURL retain];
+ method = [aMethod retain];
+ parameters = [theParameters retain];
+ files = [theFiles retain];
+ fetcher = nil;
+ request = nil;
+ }
return self;
}
View
15 OAConsumer.m
@@ -31,13 +31,20 @@ @implementation OAConsumer
#pragma mark init
-- (id)initWithKey:(const NSString *)aKey secret:(const NSString *)aSecret {
- [super init];
- self.key = [aKey retain];
- self.secret = [aSecret retain];
+- (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret {
+ if ((self = [super init])) {
+ self.key = aKey;
+ self.secret = aSecret;
+ }
return self;
}
+- (void)dealloc {
+ [key release];
+ [secret release];
+ [super dealloc];
+}
+
- (BOOL)isEqual:(id)object {
if ([object isKindOfClass:[self class]]) {
return [self isEqualToConsumer:(OAConsumer*)object];
View
5 OADataFetcher.m
@@ -30,8 +30,9 @@
@implementation OADataFetcher
- (id)init {
- [super init];
- responseData = [[NSMutableData alloc] init];
+ if ((self = [super init])) {
+ responseData = [[NSMutableData alloc] init];
+ }
return self;
}
View
4 OAMutableURLRequest.h
@@ -50,13 +50,13 @@
consumer:(OAConsumer *)aConsumer
token:(OAToken *)aToken
realm:(NSString *)aRealm
-signatureProvider:(id<OASignatureProviding, NSObject>)aProvider;
+signatureProvider:(id<OASignatureProviding>)aProvider;
- (id)initWithURL:(NSURL *)aUrl
consumer:(OAConsumer *)aConsumer
token:(OAToken *)aToken
realm:(NSString *)aRealm
-signatureProvider:(id<OASignatureProviding, NSObject>)aProvider
+signatureProvider:(id<OASignatureProviding>)aProvider
nonce:(NSString *)aNonce
timestamp:(NSString *)aTimestamp;
View
63 OAMutableURLRequest.m
@@ -42,35 +42,36 @@ - (id)initWithURL:(NSURL *)aUrl
consumer:(OAConsumer *)aConsumer
token:(OAToken *)aToken
realm:(NSString *)aRealm
-signatureProvider:(id<OASignatureProviding, NSObject>)aProvider {
- [super initWithURL:aUrl
+signatureProvider:(id<OASignatureProviding>)aProvider {
+ if ((self = [super initWithURL:aUrl
cachePolicy:NSURLRequestReloadIgnoringCacheData
- timeoutInterval:10.0];
+ timeoutInterval:10.0])) {
- consumer = [aConsumer retain];
-
- // empty token for Unauthorized Request Token transaction
- if (aToken == nil) {
- token = [[OAToken alloc] init];
- } else {
- token = [aToken retain];
- }
-
- if (aRealm == nil) {
- realm = @"";
- } else {
- realm = [aRealm copy];
- }
-
- // default to HMAC-SHA1
- if (aProvider == nil) {
- signatureProvider = [[OAHMAC_SHA1SignatureProvider alloc] init];
- } else {
- signatureProvider = [aProvider retain];
- }
-
- [self _generateTimestamp];
- [self _generateNonce];
+ consumer = [aConsumer retain];
+
+ // empty token for Unauthorized Request Token transaction
+ if (aToken == nil) {
+ token = [[OAToken alloc] init];
+ } else {
+ token = [aToken retain];
+ }
+
+ if (aRealm == nil) {
+ realm = @"";
+ } else {
+ realm = [aRealm copy];
+ }
+
+ // default to HMAC-SHA1
+ if (aProvider == nil) {
+ signatureProvider = [[OAHMAC_SHA1SignatureProvider alloc] init];
+ } else {
+ signatureProvider = [aProvider retain];
+ }
+
+ [self _generateTimestamp];
+ [self _generateNonce];
+ }
return self;
}
@@ -81,7 +82,7 @@ - (id)initWithURL:(NSURL *)aUrl
consumer:(OAConsumer *)aConsumer
token:(OAToken *)aToken
realm:(NSString *)aRealm
-signatureProvider:(id<OASignatureProviding, NSObject>)aProvider
+signatureProvider:(id<OASignatureProviding>)aProvider
nonce:(NSString *)aNonce
timestamp:(NSString *)aTimestamp {
[self initWithURL:aUrl
@@ -210,9 +211,11 @@ - (void) dealloc
{
[consumer release];
[token release];
- [(NSObject*)signatureProvider release];
+ [signatureProvider release];
[timestamp release];
- CFRelease(nonce);
+ if (nonce) {
+ CFRelease(nonce);
+ }
[super dealloc];
}
View
14 OAProblem.h
@@ -22,22 +22,22 @@ enum {
};
@interface OAProblem : NSObject {
- const NSString *problem;
+ NSString *problem;
}
-@property (readonly) const NSString *problem;
+@property (readonly) NSString *problem;
-- (id)initWithProblem:(const NSString *)aProblem;
-- (id)initWithResponseBody:(const NSString *)response;
+- (id)initWithProblem:(NSString *)aProblem;
+- (id)initWithResponseBody:(NSString *)response;
- (BOOL)isEqualToProblem:(OAProblem *)aProblem;
-- (BOOL)isEqualToString:(const NSString *)aProblem;
+- (BOOL)isEqualToString:(NSString *)aProblem;
- (BOOL)isEqualTo:(id)aProblem;
- (int)code;
-+ (OAProblem *)problemWithResponseBody:(const NSString *)response;
++ (OAProblem *)problemWithResponseBody:(NSString *)response;
-+ (const NSArray *)validProblems;
++ (NSArray *)validProblems;
+ (OAProblem *)SignatureMethodRejected;
+ (OAProblem *)ParameterAbsent;
View
43 OAProblem.m
@@ -8,29 +8,30 @@
#import "OAProblem.h"
-const NSString *signature_method_rejected = @"signature_method_rejected";
-const NSString *parameter_absent = @"parameter_absent";
-const NSString *version_rejected = @"version_rejected";
-const NSString *consumer_key_unknown = @"consumer_key_unknown";
-const NSString *token_rejected = @"token_rejected";
-const NSString *signature_invalid = @"signature_invalid";
-const NSString *nonce_used = @"nonce_used";
-const NSString *timestamp_refused = @"timestamp_refused";
-const NSString *token_expired = @"token_expired";
-const NSString *token_not_renewable = @"token_not_renewable";
+NSString *signature_method_rejected = @"signature_method_rejected";
+NSString *parameter_absent = @"parameter_absent";
+NSString *version_rejected = @"version_rejected";
+NSString *consumer_key_unknown = @"consumer_key_unknown";
+NSString *token_rejected = @"token_rejected";
+NSString *signature_invalid = @"signature_invalid";
+NSString *nonce_used = @"nonce_used";
+NSString *timestamp_refused = @"timestamp_refused";
+NSString *token_expired = @"token_expired";
+NSString *token_not_renewable = @"token_not_renewable";
@implementation OAProblem
@synthesize problem;
-- (id)initWithPointer:(const NSString *) aPointer
+- (id)initWithPointer:(NSString *) aPointer
{
- [super init];
- problem = aPointer;
+ if ((self = [super init])) {
+ problem = [aPointer copy];
+ }
return self;
}
-- (id)initWithProblem:(const NSString *) aProblem
+- (id)initWithProblem:(NSString *) aProblem
{
NSUInteger idx = [[OAProblem validProblems] indexOfObject:aProblem];
if (idx == NSNotFound) {
@@ -40,7 +41,7 @@ - (id)initWithProblem:(const NSString *) aProblem
return [self initWithPointer: [[OAProblem validProblems] objectAtIndex:idx]];
}
-- (id)initWithResponseBody:(const NSString *) response
+- (id)initWithResponseBody:(NSString *) response
{
NSArray *fields = [response componentsSeparatedByString:@"&"];
for (NSString *field in fields) {
@@ -53,12 +54,18 @@ - (id)initWithResponseBody:(const NSString *) response
return nil;
}
-+ (OAProblem *)problemWithResponseBody:(const NSString *) response
+- (void)dealloc
+{
+ [problem release];
+ [super dealloc];
+}
+
++ (OAProblem *)problemWithResponseBody:(NSString *) response
{
return [[[OAProblem alloc] initWithResponseBody:response] autorelease];
}
-+ (const NSArray *)validProblems
++ (NSArray *)validProblems
{
static NSArray *array;
if (!array) {
@@ -83,7 +90,7 @@ - (BOOL)isEqualToProblem:(OAProblem *) aProblem
return [problem isEqualToString:(NSString *)aProblem->problem];
}
-- (BOOL)isEqualToString:(const NSString *) aProblem
+- (BOOL)isEqualToString:(NSString *) aProblem
{
return [problem isEqualToString:(NSString *)aProblem];
}
View
14 OARequestParameter.m
@@ -31,12 +31,20 @@ @implementation OARequestParameter
@synthesize name, value;
- (id)initWithName:(NSString *)aName value:(NSString *)aValue {
- [super init];
- self.name = aName;
- self.value = aValue;
+ if ((self = [super init])) {
+ self.name = aName;
+ self.value = aValue;
+ }
return self;
}
+- (void)dealloc
+{
+ [name release];
+ [value release];
+ [super dealloc];
+}
+
- (NSString *)URLEncodedName {
return self.name;
// return [self.name encodedURLParameterString];
View
18 OAServiceTicket.m
@@ -31,14 +31,22 @@ @implementation OAServiceTicket
@synthesize request, response, data, didSucceed;
- (id)initWithRequest:(OAMutableURLRequest *)aRequest response:(NSURLResponse *)aResponse data:(NSData *)aData didSucceed:(BOOL)success {
- [super init];
- request = aRequest;
- response = aResponse;
- data = aData;
- didSucceed = success;
+ if ((self = [super init])) {
+ request = [aRequest retain];
+ response = [aResponse retain];
+ data = [aData retain];
+ didSucceed = success;
+ }
return self;
}
+- (void)dealloc {
+ [request release];
+ [response release];
+ [data release];
+ [super dealloc];
+}
+
- (NSString *)body
{
if (!data) {
View
2 OASignatureProviding.h
@@ -26,7 +26,7 @@
#import <Foundation/Foundation.h>
-@protocol OASignatureProviding
+@protocol OASignatureProviding <NSObject>
- (NSString *)name;
- (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret;
View
2 OAToken.h
@@ -41,7 +41,7 @@
@property(retain, readwrite) NSString *session;
@property(retain, readwrite) NSNumber *duration;
@property(retain, readwrite) NSString *verifier;
-@property(retain, readwrite) NSDictionary *attributes;
+@property(nonatomic, retain, readwrite) NSDictionary *attributes;
@property(readwrite, getter=isForRenewal) BOOL forRenewal;
- (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret;
View
20 OAToken.m
@@ -55,15 +55,16 @@ - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret {
- (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret session:(NSString *)aSession
duration:(NSNumber *)aDuration attributes:(NSDictionary *)theAttributes created:(NSDate *)creation
renewable:(BOOL)renew {
- [super init];
- self.key = aKey;
- self.secret = aSecret;
- self.session = aSession;
- self.duration = aDuration;
- self.attributes = theAttributes;
- created = [creation retain];
- renewable = renew;
- forRenewal = NO;
+ if ((self = [super init])) {
+ self.key = aKey;
+ self.secret = aSecret;
+ self.session = aSession;
+ self.duration = aDuration;
+ self.attributes = theAttributes;
+ created = [creation retain];
+ renewable = renew;
+ forRenewal = NO;
+ }
return self;
}
@@ -138,6 +139,7 @@ - (id)initWithUserDefaultsUsingServiceProviderName:(const NSString *)provider pr
- (void)dealloc {
self.key = nil;
self.secret = nil;
+ self.session = nil;
self.duration = nil;
self.verifier = nil;
self.attributes = nil;
View
29 OATokenManager.m
@@ -51,20 +51,21 @@ - (id)initWithConsumer:(OAConsumer *)aConsumer token:(OAToken *)aToken oauthBase
realm:(const NSString *)aRealm callback:(const NSString *)aCallback
delegate:(NSObject <OATokenManagerDelegate> *)aDelegate {
- [super init];
- consumer = [aConsumer retain];
- acToken = nil;
- reqToken = nil;
- initialToken = [aToken retain];
- authorizedTokenKey = nil;
- oauthBase = [base copy];
- realm = [aRealm copy];
- callback = [aCallback copy];
- delegate = aDelegate;
- calls = [[NSMutableArray alloc] init];
- selectors = [[NSMutableArray alloc] init];
- delegates = [[NSMutableDictionary alloc] init];
- isDispatching = NO;
+ if ((self = [super init])) {
+ consumer = [aConsumer retain];
+ acToken = nil;
+ reqToken = nil;
+ initialToken = [aToken retain];
+ authorizedTokenKey = nil;
+ oauthBase = [base copy];
+ realm = [aRealm copy];
+ callback = [aCallback copy];
+ delegate = aDelegate;
+ calls = [[NSMutableArray alloc] init];
+ selectors = [[NSMutableArray alloc] init];
+ delegates = [[NSMutableDictionary alloc] init];
+ isDispatching = NO;
+ }
return self;
}

0 comments on commit 9b1db6c

Please sign in to comment.