Fix NSE Leak (#2022)

This commit is contained in:
Mauro
2023-11-03 21:30:58 +01:00
committed by GitHub
parent 4985d410b3
commit ce72a9b5f2
11 changed files with 77 additions and 22 deletions
@@ -1,4 +1,4 @@
// Generated using Sourcery 2.1.2 — https://github.com/krzysztofzablocki/Sourcery
// Generated using Sourcery 2.1.1 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
// swiftlint:disable all
@@ -575,13 +575,18 @@ class SDKClientMock: SDKClientProtocol {
}
public var setDelegateDelegateReceivedDelegate: ClientDelegate?
public var setDelegateDelegateReceivedInvocations: [ClientDelegate?] = []
public var setDelegateDelegateClosure: ((ClientDelegate?) -> Void)?
public var setDelegateDelegateReturnValue: TaskHandle?
public var setDelegateDelegateClosure: ((ClientDelegate?) -> TaskHandle?)?
public func setDelegate(delegate: ClientDelegate?) {
public func setDelegate(delegate: ClientDelegate?) -> TaskHandle? {
setDelegateDelegateCallsCount += 1
setDelegateDelegateReceivedDelegate = delegate
setDelegateDelegateReceivedInvocations.append(delegate)
setDelegateDelegateClosure?(delegate)
if let setDelegateDelegateClosure = setDelegateDelegateClosure {
return setDelegateDelegateClosure(delegate)
} else {
return setDelegateDelegateReturnValue
}
}
//MARK: - setDisplayName
@@ -36,6 +36,8 @@ class ClientProxy: ClientProxyProtocol {
private var syncService: SyncService?
private var syncServiceStateUpdateTaskHandle: TaskHandle?
private var delegateHandle: TaskHandle?
// These following summary providers both operate on the same allRooms() list but
// can apply their own filtering and pagination
private(set) var roomSummaryProvider: RoomSummaryProviderProtocol?
@@ -69,8 +71,10 @@ class ClientProxy: ClientProxyProtocol {
private var hasEncounteredAuthError = false
deinit {
client.setDelegate(delegate: nil)
stopSync()
stopSync { [delegateHandle] in
// The delegate handle needs to be cancelled always after the sync stops
delegateHandle?.cancel()
}
}
let callbacks = PassthroughSubject<ClientProxyCallback, Never>()
@@ -98,7 +102,7 @@ class ClientProxy: ClientProxyProtocol {
secureBackupController = SecureBackupController(encryption: client.encryption())
client.setDelegate(delegate: ClientDelegateWrapper { [weak self] isSoftLogout in
delegateHandle = client.setDelegate(delegate: ClientDelegateWrapper { [weak self] isSoftLogout in
self?.hasEncounteredAuthError = true
self?.callbacks.send(.receivedAuthError(isSoftLogout: isSoftLogout))
})
@@ -168,10 +172,17 @@ class ClientProxy: ClientProxyProtocol {
}
func stopSync() {
stopSync(completion: nil)
}
private func stopSync(completion: (() -> Void)?) {
MXLog.info("Stopping sync")
Task {
do {
defer {
completion?()
}
try await syncService?.stop()
} catch {
MXLog.error("Failed stopping the sync service with error: \(error)")
@@ -67,7 +67,8 @@ class ElementCallWidgetDriver: WidgetCapabilitiesProvider, ElementCallWidgetDriv
skipLobby: true,
confineToRoom: true,
font: nil,
analyticsId: nil)) else {
analyticsId: nil,
encryption: .unencrypted)) else {
return .failure(.failedBuildingWidgetSettings)
}
@@ -59,9 +59,13 @@ extension MediaFileHandleProxy: Hashable {
/// An unmanaged file handle that can be created direct from a URL.
///
/// This type allows for mocking but doesn't provide the automatic clean-up mechanism provided by the SDK.
private struct UnmanagedMediaFileHandle: MediaFileHandleProtocol {
private class UnmanagedMediaFileHandle: MediaFileHandleProtocol {
let url: URL
init(url: URL) {
self.url = url
}
func path() -> String {
url.path()
}