1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

WiFiClient: don’t destroy ClientContext on ::stop

Reported in https://github.com/esp8266/Arduino/issues/4078.

WiFiClient::stopAll, called from a WiFi disconnected event handler,
could be called while WiFiClient::connect was in progress. This issue
was initially fixed in #4194, by testing `this` pointer for being
non-null in ClientContext::connect.

This change delegates deletion of ClientContext to WiFiClient
destructor. WiFiClient::stop only calls ClientContext::stop, which
closes/aborts the connection.
This commit is contained in:
Ivan Grokhotkov
2018-02-19 16:29:34 +03:00
committed by Ivan Grokhotkov
parent 28d8a41219
commit ee5a1e2804
3 changed files with 70 additions and 16 deletions

View File

@ -272,8 +272,7 @@ void WiFiClient::stop()
if (!_client)
return;
_client->unref();
_client = 0;
_client->close();
}
uint8_t WiFiClient::connected()

View File

@ -107,17 +107,15 @@ public:
void unref()
{
if(this != 0) {
DEBUGV(":ur %d\r\n", _refcnt);
if(--_refcnt == 0) {
discard_received();
close();
if(_discard_cb) {
_discard_cb(_discard_cb_arg, this);
}
DEBUGV(":del\r\n");
delete this;
DEBUGV(":ur %d\r\n", _refcnt);
if(--_refcnt == 0) {
discard_received();
close();
if(_discard_cb) {
_discard_cb(_discard_cb_arg, this);
}
DEBUGV(":del\r\n");
delete this;
}
}
@ -131,13 +129,13 @@ public:
_op_start_time = millis();
// This delay will be interrupted by esp_schedule in the connect callback
delay(_timeout_ms);
// WiFi may have vanished during the delay (#4078)
if (!this || !_pcb) {
DEBUGV(":vnsh\r\n");
_connect_pending = 0;
if (!_pcb) {
DEBUGV(":cabrt\r\n");
return 0;
}
_connect_pending = 0;
if (state() != ESTABLISHED) {
DEBUGV(":ctmo\r\n");
abort();
return 0;
}