Skip to content

Commit 497ab25

Browse files
committed
fix some memory leek
still looses 40Byte some where?!
1 parent 6ed7dfe commit 497ab25

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

libraries/ESP8266httpClient/src/ESP8266httpClient.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
#include "ESP8266httpClient.h"
3030

31+
/**
32+
* constractor
33+
*/
3134
httpClient::httpClient() {
3235
_tcp = NULL;
3336
_tcps = NULL;
@@ -43,17 +46,35 @@ httpClient::httpClient() {
4346

4447
}
4548

49+
/**
50+
* deconstractor
51+
*/
4652
httpClient::~httpClient() {
47-
if(connected()) {
53+
54+
if(_tcps) {
55+
_tcps->stop();
56+
_tcps->~WiFiClientSecure();
57+
_tcps = NULL;
58+
_tcp = NULL;
59+
} else if(_tcp) {
4860
_tcp->stop();
61+
_tcp->~WiFiClient();
62+
_tcp = NULL;
4963
}
5064

5165
if(_currentHeaders) {
5266
delete[] _currentHeaders;
5367
}
54-
_headerKeysCount = 0;
5568
}
5669

70+
/**
71+
* begin
72+
* @param host const char *
73+
* @param port uint16_t
74+
* @param url const char *
75+
* @param https bool
76+
* @param httpsFingerprint const char *
77+
*/
5778
void httpClient::begin(const char *host, uint16_t port, const char * url, bool https, const char * httpsFingerprint) {
5879

5980
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port:%d url: %s https: %d httpsFingerprint: %s\n", host, port, url, https, httpsFingerprint);
@@ -98,7 +119,7 @@ void httpClient::end(void) {
98119
*/
99120
bool httpClient::connected() {
100121
if(_tcp) {
101-
return _tcp->connected();
122+
return (_tcp->connected() || (_tcp->available() > 0));
102123
}
103124
return false;
104125
}
@@ -317,12 +338,22 @@ bool httpClient::connect(void) {
317338
return true;
318339
}
319340

341+
320342
if(_https) {
321343
DEBUG_HTTPCLIENT("[HTTP-Client] connect https...\n");
344+
if(_tcps) {
345+
_tcps->~WiFiClient();
346+
_tcps = NULL;
347+
_tcp = NULL;
348+
}
322349
_tcps = new WiFiClientSecure();
323350
_tcp = _tcps;
324351
} else {
325352
DEBUG_HTTPCLIENT("[HTTP-Client] connect http...\n");
353+
if(_tcp) {
354+
_tcp->~WiFiClient();
355+
_tcp = NULL;
356+
}
326357
_tcp = new WiFiClient();
327358
}
328359

0 commit comments

Comments
 (0)