mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Fix mem leak in SSL server, allow for concurrent client and server connections w/o interference (#4305)
* Fix leak on multiple SSL server connections Fixes #4302 The refcnt setup for the WiFiClientSecure's SSLContext and ClientContext had issues in certain conditions, causing a massive memory leak on each SSL server connection. Depending on the state of the machine, after two or three connections it would OOM and crash. This patch replaces most of the refcnt operations with C++11 shared_ptr operations, cleaning up the code substantially and removing the leakage. Also fixes a race condition where ClientContext was free'd before the SSLContext was stopped/shutdown. When the SSLContext tried to do ssl_free, axtls would attempt to send out the real SSL disconnect bits over the wire, however by this time the ClientContext is invalid and it would fault. * Separate client and server SSL_CTX, support both Refactor to use a separate client SSL_CTX and server SSL_CTX. This allows for separate certificates to be installed on each, and means that you can now have both a *single* client and a *single* server running in parallel at the same time, as they'll have separate memory areas. Tested using mqtt_esp8266 SSL client with a client certificate and a WebServerSecure with its own custom certificate and key in parallel. * Add brackets around a couple if-else clauses
This commit is contained in:
committed by
Develo
parent
cda72a07e0
commit
bf5a0f24dc
@ -32,8 +32,6 @@ class WiFiClientSecure : public WiFiClient {
|
||||
public:
|
||||
WiFiClientSecure();
|
||||
~WiFiClientSecure() override;
|
||||
WiFiClientSecure(const WiFiClientSecure&);
|
||||
WiFiClientSecure& operator=(const WiFiClientSecure&);
|
||||
|
||||
int connect(IPAddress ip, uint16_t port) override;
|
||||
int connect(const String host, uint16_t port) override;
|
||||
@ -91,7 +89,7 @@ protected:
|
||||
int _connectSSL(const char* hostName);
|
||||
bool _verifyDN(const char* name);
|
||||
|
||||
SSLContext* _ssl = nullptr;
|
||||
std::shared_ptr<SSLContext> _ssl = nullptr;
|
||||
};
|
||||
|
||||
#endif //wificlientsecure_h
|
||||
|
Reference in New Issue
Block a user