Skip to content

Commit 6debe43

Browse files
authored
Fix some PointOfSaleAggregateModel memory leaks (#15055)
2 parents 9c04b30 + 33f516d commit 6debe43

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Hardware/Hardware/CardReader/StripeCardReader/StripeCardReaderService.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,13 @@ extension StripeCardReaderService: CardReaderService {
430430
}
431431

432432
paymentCancellable.cancel({ [weak self] error in
433-
if error == nil {
433+
// If the action could not be canceled,
434+
// e.g. it has already completed, the completion block will be called with an
435+
// error. Otherwise, the completion block will be called with nil.
436+
if let error {
437+
let underlyingError = Self.logAndDecodeError(error)
438+
promise(.failure(CardReaderServiceError.paymentCancellation(underlyingError: underlyingError)))
439+
} else {
434440
self?.paymentCancellable = nil
435441
cancelPaymentIntent()
436442
}

WooCommerce/Classes/POS/Card Present Payments/CardPresentPaymentService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ final class CardPresentPaymentService: CardPresentPaymentFacade {
108108
DDLogError("Attempting to cancel the payment has failed \(error)")
109109
}
110110

111+
paymentTask?.cancel()
111112
connectionControllerManager.knownReaderProvider.forgetCardReader()
112113

113114
return await withCheckedContinuation { continuation in

WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ extension PointOfSaleAggregateModel {
184184
}
185185
}
186186
.removeDuplicates()
187-
.sink { _ in
187+
.sink { [weak self] _ in
188188
Task { @MainActor [weak self] in
189189
await self?.collectCardPayment()
190190
}

0 commit comments

Comments
 (0)