Browse Source

Merge pull request #1104 from deltachat/fix_potential_leak

always weak reference self in asyncAfter code
bjoern 4 years ago
parent
commit
adda39465f
1 changed files with 12 additions and 2 deletions
  1. 12 2
      deltachat-ios/AppDelegate.swift

+ 12 - 2
deltachat-ios/AppDelegate.swift

@@ -119,7 +119,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         dcContext.maybeStartIo()
         dcContext.maybeNetwork()
 
-        DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
+        DispatchQueue.main.asyncAfter(deadline: .now() + 10) { [weak self] in
+            guard let self = self else {
+                completionHandler(.failed)
+                return
+            }
+
             if !self.appIsInForeground {
                 self.dcContext.stopIo()
             }
@@ -386,7 +391,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         dcContext.maybeStartIo()
         dcContext.maybeNetwork()
 
-        DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
+        DispatchQueue.main.asyncAfter(deadline: .now() + 10) { [weak self] in
+            guard let self = self else {
+                completionHandler(.failed)
+                return
+            }
+
             if !self.appIsInForeground {
                 self.dcContext.stopIo()
             }