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>
This commit is contained in:
Andrej Mihajlov 2020-06-19 12:42:35 +02:00 committed by Jason A. Donenfeld
parent 35300d1c5f
commit e9bd6e576f
1 changed files with 3 additions and 1 deletions

View File

@ -52,7 +52,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotSetNetworkSettings) startTunnelCompletionHandler(PacketTunnelProviderError.couldNotSetNetworkSettings)
} else { } else {
self.networkMonitor = NWPathMonitor() 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")) self.networkMonitor!.start(queue: DispatchQueue(label: "NetworkMonitor"))
let fileDescriptor = (self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as? Int32) ?? -1 let fileDescriptor = (self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as? Int32) ?? -1