From 6563e2e2b2a211dff298bc84c71c091f86154261 Mon Sep 17 00:00:00 2001 From: Will Miles Date: Fri, 1 Aug 2025 21:32:00 -0400 Subject: [PATCH] Restore abort dispose semantics Calling `AsyncClient::abort()` will now enqueue an error event, as it did prior to #79. This fixes memory leaks caused by missing dispose callbacks. --- src/AsyncTCP.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/AsyncTCP.cpp b/src/AsyncTCP.cpp index e373927..3abda7c 100644 --- a/src/AsyncTCP.cpp +++ b/src/AsyncTCP.cpp @@ -656,16 +656,12 @@ static esp_err_t _tcp_close(tcp_pcb **pcb, AsyncClient *client) { static err_t _tcp_abort_api(struct tcpip_api_call_data *api_call_msg) { // Like close(), we must ensure that the queue is cleared tcp_api_call_t *msg = (tcp_api_call_t *)api_call_msg; - msg->err = ERR_CONN; if (*msg->pcb) { - tcp_pcb *pcb = *msg->pcb; - _reset_tcp_callbacks(pcb, msg->close); - tcp_abort(pcb); + tcp_abort(*msg->pcb); *msg->pcb = nullptr; // PCB is now the property of LwIP - msg->err = ERR_OK; + msg->err = ERR_ABRT; } else { - // Ensure there is not an error event queued for this client - _remove_events_for_client(msg->close); + msg->err = ERR_CONN; } return msg->err; } @@ -921,11 +917,8 @@ void AsyncClient::close(bool now) { } int8_t AsyncClient::abort() { - if (_pcb) { - _tcp_abort(&_pcb, this); - // _pcb is now NULL - } - return ERR_ABRT; + return _tcp_abort(&_pcb, this); + // _pcb is now NULL } size_t AsyncClient::space() const {