aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-06-19 12:42:35 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2020-06-25 17:50:15 -0600
commite9bd6e576f89016fbb4ff0a7944a4f3cd8ca863d (patch)
tree60c7ff97be2595ff49f3e78823d473fcaf324e10
parentRefactor interface name query (diff)
downloadwireguard-apple-e9bd6e576f89016fbb4ff0a7944a4f3cd8ca863d.tar.xz
wireguard-apple-e9bd6e576f89016fbb4ff0a7944a4f3cd8ca863d.zip
Fix retain cycle between NWPathMonitor and PacketTunnelProvider
See: https://www.marisibrothers.com/2017/04/memory-leak-in-swift-assigning-function.html Signed-off-by: Andrej Mihajlov <and@mullvad.net> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift4
1 files changed, 3 insertions, 1 deletions
diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
index 2f7062fe..987c290f 100644
--- a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
+++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
@@ -52,7 +52,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotSetNetworkSettings)
} else {
self.networkMonitor = NWPathMonitor()
- self.networkMonitor!.pathUpdateHandler = self.pathUpdate
+ self.networkMonitor!.pathUpdateHandler = { [weak self] path in
+ self?.pathUpdate(path: path)
+ }
self.networkMonitor!.start(queue: DispatchQueue(label: "NetworkMonitor"))
let fileDescriptor = (self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as? Int32) ?? -1