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:
parent
35300d1c5f
commit
e9bd6e576f
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue