From 28d5769c69d1afa88ead5e8a382bedd64ad21f4c Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Wed, 16 Aug 2017 11:47:36 +0200 Subject: [PATCH 1/4] Fixes issue related to heap corruption - a block was capturing self in dealloc through _stopMonitoring - this removed the retain cycle at dealloc --- Parse/Internal/PFEventuallyQueue.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Parse/Internal/PFEventuallyQueue.m b/Parse/Internal/PFEventuallyQueue.m index 68d31aad5..79ce9bd51 100644 --- a/Parse/Internal/PFEventuallyQueue.m +++ b/Parse/Internal/PFEventuallyQueue.m @@ -383,7 +383,6 @@ - (void)_stopMonitoringNetworkReachability { [[PFReachability sharedParseReachability] removeListener:self]; self.monitorsReachability = NO; - self.connected = YES; #endif } From f25e3530b409762b3db25bc53bbc589ee6c11b57 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Fri, 18 Aug 2017 12:21:55 -0400 Subject: [PATCH 2/4] Better handling of EventuallyQueue termination --- Parse/Internal/PFEventuallyQueue.h | 2 +- Parse/Internal/PFEventuallyQueue.m | 10 +++++----- Parse/Internal/PFReachability.m | 2 ++ Parse/Internal/ParseManager.m | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Parse/Internal/PFEventuallyQueue.h b/Parse/Internal/PFEventuallyQueue.h index 7e6a2eb64..dd16becf1 100644 --- a/Parse/Internal/PFEventuallyQueue.h +++ b/Parse/Internal/PFEventuallyQueue.h @@ -67,7 +67,7 @@ extern NSTimeInterval const PFEventuallyQueueDefaultTimeoutRetryInterval; - (void)start NS_REQUIRES_SUPER; - (void)resume NS_REQUIRES_SUPER; - (void)pause NS_REQUIRES_SUPER; -- (void)stop NS_REQUIRES_SUPER; +- (void)terminate NS_REQUIRES_SUPER; - (void)removeAllCommands NS_REQUIRES_SUPER; @end diff --git a/Parse/Internal/PFEventuallyQueue.m b/Parse/Internal/PFEventuallyQueue.m index 79ce9bd51..7eddfbabc 100644 --- a/Parse/Internal/PFEventuallyQueue.m +++ b/Parse/Internal/PFEventuallyQueue.m @@ -80,10 +80,6 @@ - (instancetype)initWithDataSource:(id)dataSource return self; } -- (void)dealloc { - [self _stopMonitoringNetworkReachability]; -} - ///-------------------------------------- #pragma mark - Enqueueing Commands ///-------------------------------------- @@ -197,7 +193,8 @@ - (void)pause { dispatch_suspend(_processingQueueSource); } -- (void)stop { +- (void)terminate { + [self _stopMonitoringNetworkReachability]; dispatch_source_cancel(_processingQueueSource); } @@ -392,9 +389,11 @@ - (void)_stopMonitoringNetworkReachability { /** Manually sets the network connection status. */ - (void)setConnected:(BOOL)connected { + @weakify(self); BFTaskCompletionSource *barrier = [BFTaskCompletionSource taskCompletionSource]; dispatch_async(_processingQueue, ^{ dispatch_sync(_synchronizationQueue, ^{ + @strongify(self); if (self.connected != connected) { _connected = connected; if (connected) { @@ -406,6 +405,7 @@ - (void)setConnected:(BOOL)connected { }); if (connected) { dispatch_async(_synchronizationQueue, ^{ + @strongify(self); if (_retryingSemaphore) { dispatch_semaphore_signal(_retryingSemaphore); } diff --git a/Parse/Internal/PFReachability.m b/Parse/Internal/PFReachability.m index d25f10b88..4aa31b332 100644 --- a/Parse/Internal/PFReachability.m +++ b/Parse/Internal/PFReachability.m @@ -130,7 +130,9 @@ - (void)addListener:(id)listener { } - (void)removeListener:(id)listener { + @weakify(listener); dispatch_barrier_sync(_synchronizationQueue, ^{ + @strongify(listener); [_listenersArray filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { id weakObject = [evaluatedObject weakObject]; return (weakObject == nil || weakObject == listener); diff --git a/Parse/Internal/ParseManager.m b/Parse/Internal/ParseManager.m index b6c9d4af3..ac3acc464 100644 --- a/Parse/Internal/ParseManager.m +++ b/Parse/Internal/ParseManager.m @@ -181,8 +181,8 @@ - (PFEventuallyQueue *)eventuallyQueue { if (commandCache.commandCount > 0) { [commandCache removeAllCommands]; } - // we won't need it after stop everything... - [commandCache stop]; + // we won't need it after, terminate... + [commandCache terminate]; } } #endif From ede7954735d3ceb0fc15f88044e965a9381b702e Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Mon, 21 Aug 2017 15:43:14 -0400 Subject: [PATCH 3/4] Fixes issue for cocoapods --- Parse/Internal/PFEventuallyQueue.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Parse/Internal/PFEventuallyQueue.m b/Parse/Internal/PFEventuallyQueue.m index 7eddfbabc..56279464f 100644 --- a/Parse/Internal/PFEventuallyQueue.m +++ b/Parse/Internal/PFEventuallyQueue.m @@ -406,8 +406,8 @@ - (void)setConnected:(BOOL)connected { if (connected) { dispatch_async(_synchronizationQueue, ^{ @strongify(self); - if (_retryingSemaphore) { - dispatch_semaphore_signal(_retryingSemaphore); + if (self->_retryingSemaphore) { + dispatch_semaphore_signal(self->_retryingSemaphore); } }); } From 11bcf6beb0abb59245a623ef0f70d1aeb01e0548 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Mon, 21 Aug 2017 18:18:33 -0400 Subject: [PATCH 4/4] fixup! Fixes issue for cocoapods --- Parse/Internal/PFEventuallyQueue.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Parse/Internal/PFEventuallyQueue.m b/Parse/Internal/PFEventuallyQueue.m index 56279464f..4d43130d1 100644 --- a/Parse/Internal/PFEventuallyQueue.m +++ b/Parse/Internal/PFEventuallyQueue.m @@ -405,9 +405,8 @@ - (void)setConnected:(BOOL)connected { }); if (connected) { dispatch_async(_synchronizationQueue, ^{ - @strongify(self); - if (self->_retryingSemaphore) { - dispatch_semaphore_signal(self->_retryingSemaphore); + if (_retryingSemaphore) { + dispatch_semaphore_signal(_retryingSemaphore); } }); }