Clear write queue BEFORE calling discard callback

The discard callback (installed via onDisconnect()) can legitimately
decide to destroy the AsyncTCP client, calling the destructors which in
turn invalidate the write mutex object. Prior to this commit, calling
_clearWriteQueue() (which takes said write mutex) risked accessing
uninitialized memory and causing memory corruption. Fixed.
This commit is contained in:
Alex Villacís Lasso
2021-02-16 19:54:43 -05:00
parent caefb971a4
commit d5cf17ff65

View File

@@ -718,9 +718,9 @@ void AsyncClient::_close(void)
_socket = -1;
xSemaphoreGive(_asyncsock_mutex);
_clearWriteQueue();
if (_discard_cb) _discard_cb(_discard_cb_arg, this);
_removeAllCallbacks();
_clearWriteQueue();
}
void AsyncClient::_error(int8_t err)
@@ -731,10 +731,10 @@ void AsyncClient::_error(int8_t err)
_socket = -1;
xSemaphoreGive(_asyncsock_mutex);
_clearWriteQueue();
if (_error_cb) _error_cb(_error_cb_arg, this, err);
if (_discard_cb) _discard_cb(_discard_cb_arg, this);
_removeAllCallbacks();
_clearWriteQueue();
}
size_t AsyncClient::space()