From 9da9bc565fa94a794eae2e411c90d201febb23e1 Mon Sep 17 00:00:00 2001 From: motrab Date: Sat, 16 Feb 2019 20:31:51 +0100 Subject: [PATCH] Remote close() caused null reference in write --- src/ESPAsyncTCPbuffer.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/ESPAsyncTCPbuffer.cpp b/src/ESPAsyncTCPbuffer.cpp index 8bf44fb..72f6139 100644 --- a/src/ESPAsyncTCPbuffer.cpp +++ b/src/ESPAsyncTCPbuffer.cpp @@ -330,7 +330,7 @@ void AsyncTCPbuffer::_sendBuffer() { return; } - while((_client->space() > 0) && (_TXbufferRead->available() > 0) && _client->canSend()) { + while(_client != NULL && (_client->space() > 0) && (_TXbufferRead->available() > 0) && _client->canSend()) { available = _TXbufferRead->available(); @@ -347,14 +347,16 @@ void AsyncTCPbuffer::_sendBuffer() { // read data from buffer _TXbufferRead->peek(out, available); - // send data - size_t send = _client->write((const char*) out, available); - if(send != available) { - DEBUG_ASYNC_TCP("[A-TCP] write failed send: %d available: %d \n", send, available); - } + if (_client) { + // send data + size_t send = _client->write((const char*) out, available); + if(send != available) { + DEBUG_ASYNC_TCP("[A-TCP] write failed send: %d available: %d \n", send, available); + } - // remove really send data from buffer - _TXbufferRead->remove(send); + // remove really send data from buffer + _TXbufferRead->remove(send); + } // if buffer is empty and there is a other buffer in chain delete the empty one if(_TXbufferRead->available() == 0 && _TXbufferRead->next != NULL) {