From 70787ce4cf4eaa57b175504c031be2e997fbd84a Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 23 Jul 2012 16:20:11 -0700 Subject: [PATCH] [Issue #398] Adding state checks to AFURLConnectionOperation -pause to prevent likely memry issues when cancelling a non-existint connection --- AFNetworking/AFURLConnectionOperation.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 9686580..d378465 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -355,15 +355,19 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat } - (void)pause { - if ([self isPaused]) { + if ([self isPaused] || [self isFinished]) { return; } [self.lock lock]; - self.state = AFHTTPOperationPausedState; - [self.connection performSelector:@selector(cancel) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]]; - [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidFinishNotification object:self]; + if ([self isExecuting]) { + [self.connection performSelector:@selector(cancel) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]]; + [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidFinishNotification object:self]; + } + + self.state = AFHTTPOperationPausedState; + [self.lock unlock]; }