From cdd26a9ece2f82f10d7acba46af8f6fbb6d962da Mon Sep 17 00:00:00 2001 From: chuck todd Date: Tue, 28 Jan 2020 20:18:49 -0700 Subject: [PATCH 1/3] std::shared_ptr Memory Leak clientSocketHande and _rxBuffer are std::shared_ptr, the stop() call was not correctly releasing them and the operator= had similar problems fix for #3679 --- libraries/WiFi/src/WiFiClient.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index e422b63673d..ed562be94e1 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -188,16 +188,16 @@ WiFiClient::~WiFiClient() WiFiClient & WiFiClient::operator=(const WiFiClient &other) { stop(); - clientSocketHandle = other.clientSocketHandle; - _rxBuffer = other._rxBuffer; + clientSocketHandle.reset( other.clientSocketHandle ); // clientSocketHandle = other.clientSocketHandle; + _rxBuffer.reset( other._rxBuffer); // _rxBuffer = other._rxBuffer; _connected = other._connected; return *this; } void WiFiClient::stop() { - clientSocketHandle = NULL; - _rxBuffer = NULL; + clientSocketHandle.reset(); // clientSocketHandle = NULL; + _rxBuffer.reset(); // _rxBuffer = NULL; _connected = false; } From 4ac98c94b47f7b82dd021aedddd696f8bb663bbd Mon Sep 17 00:00:00 2001 From: chuck todd Date: Tue, 28 Jan 2020 20:35:08 -0700 Subject: [PATCH 2/3] operator= second attempt --- libraries/WiFi/src/WiFiClient.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index ed562be94e1..8d7a83e973a 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -188,8 +188,10 @@ WiFiClient::~WiFiClient() WiFiClient & WiFiClient::operator=(const WiFiClient &other) { stop(); - clientSocketHandle.reset( other.clientSocketHandle ); // clientSocketHandle = other.clientSocketHandle; - _rxBuffer.reset( other._rxBuffer); // _rxBuffer = other._rxBuffer; + clientSocketHandle.reset(); + clientSocketHandle = other.clientSocketHandle; + _rxBuffer.reset(); + _rxBuffer = other._rxBuffer; _connected = other._connected; return *this; } From e7e7254f0a4c2ef94128fa12b9e8d95a7b3adf3d Mon Sep 17 00:00:00 2001 From: chuck todd Date: Tue, 28 Jan 2020 20:53:47 -0700 Subject: [PATCH 3/3] operator= third time --- libraries/WiFi/src/WiFiClient.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index 8d7a83e973a..3913208ba0b 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -188,9 +188,7 @@ WiFiClient::~WiFiClient() WiFiClient & WiFiClient::operator=(const WiFiClient &other) { stop(); - clientSocketHandle.reset(); clientSocketHandle = other.clientSocketHandle; - _rxBuffer.reset(); _rxBuffer = other._rxBuffer; _connected = other._connected; return *this;