From ab942fa9b73788ea0239b969ae4867e05fbaef4e Mon Sep 17 00:00:00 2001 From: Drew McCormack Date: Thu, 10 Aug 2017 10:19:01 +0200 Subject: [PATCH] Added a timer invalidation in a asynchronous callback. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The scheduleNextUpdateCheckFiringImmediately: method includes an asynchronous callback. It invalidates the timer before invoking the method with the callback (retrieveNextUpdateCheckInterval:), but doesn’t not invalidate again inside the callback block. The problem with this is that it is possible the timer is started during the delay. In release versions of an app, crashes have been seen due to an assertion that the NSTimer be nil when scheduling. The proposed fix is to invalidate the timer in the callback, ensuring the NSTimer is nil before scheduling. --- Sparkle/SPUUpdater.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index a5d518b1..310b2fd6 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -351,6 +351,9 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification [self.userDriver showCanCheckForUpdates:YES]; [self retrieveNextUpdateCheckInterval:^(NSTimeInterval updateCheckInterval) { + // This callback is asynchronous, so the timer may be set. Invalidate to make sure it isn't. + [self.updaterTimer invalidate]; + // How long has it been since last we checked for an update? NSDate *lastCheckDate = [self lastUpdateCheckDate]; if (!lastCheckDate) { lastCheckDate = [NSDate distantPast]; }