Skip to content

Commit 82da276

Browse files
committed
WiFi: Properly guard socket.close()
1 parent 1016c03 commit 82da276

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

libraries/WiFi/src/WiFiClient.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ void arduino::WiFiClient::flush() {
118118
}
119119

120120
void arduino::WiFiClient::stop() {
121-
sock->close();
122-
delete sock;
123-
sock = NULL;
121+
if (sock != NULL) {
122+
sock->close();
123+
//delete[] sock;
124+
sock = NULL;
125+
}
124126
}
125127

126128
uint8_t arduino::WiFiClient::connected() {

libraries/WiFi/src/WiFiClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class WiFiClient : public arduino::Client {
3333

3434
public:
3535
WiFiClient();
36+
~WiFiClient() {
37+
stop();
38+
}
3639

3740
uint8_t status();
3841
int connect(IPAddress ip, uint16_t port);

libraries/WiFi/src/WiFiServer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ size_t arduino::WiFiServer::write(const uint8_t *buf, size_t size) {
3434

3535
arduino::WiFiClient arduino::WiFiServer::available(uint8_t* status) {
3636
WiFiClient ret;
37-
TCPSocket* client = sock->accept();
38-
ret.setSocket(client);
37+
nsapi_error_t error;
38+
TCPSocket* client = sock->accept(&error);
39+
if (error != 0) {
40+
ret.setSocket(NULL);
41+
} else {
42+
ret.setSocket(client);
43+
}
3944
return ret;
4045
}

0 commit comments

Comments
 (0)