Преглед на файлове

Merge pull request #1104 from deltachat/fix_potential_leak

always weak reference self in asyncAfter code
bjoern преди 4 години
родител
ревизия
adda39465f
променени са 1 файла, в които са добавени 12 реда и са изтрити 2 реда
  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()
             }