From a58c71f4b8d1ececf3dbc7f8f2d3899b5558bab8 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 12 Jul 2017 18:04:49 -0400 Subject: [PATCH 1/2] Fix leak of call view. // FREEBIE --- Signal/src/ViewControllers/CallViewController.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Signal/src/ViewControllers/CallViewController.swift b/Signal/src/ViewControllers/CallViewController.swift index b8fdcccc8..456e3c4f8 100644 --- a/Signal/src/ViewControllers/CallViewController.swift +++ b/Signal/src/ViewControllers/CallViewController.swift @@ -147,9 +147,10 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R contactNameLabel.text = contactsManager.displayName(forPhoneIdentifier: thread.contactIdentifier()) updateAvatarImage() - NotificationCenter.default.addObserver(forName: .OWSContactsManagerSignalAccountsDidChange, object: nil, queue: nil) { _ in - Logger.info("\(self.TAG) updating avatar image") - self.updateAvatarImage() + NotificationCenter.default.addObserver(forName: .OWSContactsManagerSignalAccountsDidChange, object: nil, queue: nil) { [weak self] _ in + guard let strongSelf = self else { return } + Logger.info("\(strongSelf.TAG) updating avatar image") + strongSelf.updateAvatarImage() } assert(call != nil) From ac616d693646e053303a7e60f9af6db7443658ea Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 12 Jul 2017 18:12:27 -0400 Subject: [PATCH 2/2] =?UTF-8?q?Reject=20the=20=E2=80=9Ccall=20connected?= =?UTF-8?q?=E2=80=9D=20promise=20immediately=20when=20clearing=20a=20call.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- Signal/src/call/CallService.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index c782d487b..5dfc2b572 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -159,6 +159,7 @@ protocol CallServiceObserver: class { // Used to coordinate promises across delegate methods private var fulfillCallConnectedPromise: (() -> Void)? + private var rejectCallConnectedPromise: ((Error) -> Void)? /** * In the process of establishing a connection between the clients (ICE process) we must exchange ICE updates. @@ -328,8 +329,9 @@ protocol CallServiceObserver: class { // clients that don't support receiving ICE updates before receiving the call offer. self.readyToSendIceUpdates(call: call) - let (callConnectedPromise, fulfill, _) = Promise.pending() + let (callConnectedPromise, fulfill, reject) = Promise.pending() self.fulfillCallConnectedPromise = fulfill + self.rejectCallConnectedPromise = reject // Don't let the outgoing call ring forever. We don't support inbound ringing forever anyway. let timeout: Promise = after(interval: TimeInterval(connectingTimeoutSeconds)).then { () -> Void in @@ -620,7 +622,7 @@ protocol CallServiceObserver: class { // a more intuitive ordering. self.readyToSendIceUpdates(call: newCall) - let (promise, fulfill, _) = Promise.pending() + let (promise, fulfill, reject) = Promise.pending() let timeout: Promise = after(interval: TimeInterval(connectingTimeoutSeconds)).then { () -> Void in // rejecting a promise by throwing is safely a no-op if the promise has already been fulfilled @@ -629,6 +631,7 @@ protocol CallServiceObserver: class { // This will be fulfilled (potentially) by the RTCDataChannel delegate method self.fulfillCallConnectedPromise = fulfill + self.rejectCallConnectedPromise = reject return race(promise, timeout) }.then { @@ -1396,6 +1399,10 @@ protocol CallServiceObserver: class { Logger.info("\(TAG) clearing pendingIceUpdateMessages") self.pendingIceUpdateMessages = [] self.fulfillCallConnectedPromise = nil + if let rejectCallConnectedPromise = self.rejectCallConnectedPromise { + rejectCallConnectedPromise(CallError.obsoleteCall(description: "Terminating call")) + } + self.rejectCallConnectedPromise = nil // In case we're still waiting on the peer connection setup somewhere, we need to reject it to avoid a memory leak. // There is no harm in rejecting a previously fulfilled promise.