Memory leak -> Crash (WiFiClient connection)
Posted: Tue Jun 06, 2017 8:59 am
I seem to have a memory leak which causes the processor to crash.
Using ESP8266 (NodeMCU) board.
I've cut my code down to bare minimum to demonstrate the issue.
Application prints out loop count and free heap size.
Starts with: "LoopCount: 1, FreeHeap: 47152"
Ends with: "LoopCount: 255, FreeHeap: 416"
After that there are some crash report messages:
Then the processor hangs and eventually resets.
Using ESP8266 (NodeMCU) board.
I've cut my code down to bare minimum to demonstrate the issue.
Application prints out loop count and free heap size.
Starts with: "LoopCount: 1, FreeHeap: 47152"
Ends with: "LoopCount: 255, FreeHeap: 416"
After that there are some crash report messages:
Code: Select all
Exception (29):
epc1=0x4000e1b2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
ctx: sys
sp: 3ffffd70 end: 3fffffb0 offset: 01a0
Then the processor hangs and eventually resets.
Code: Select all
#include <ESP8266WiFi.h>
// WiFi settings
const char* ssid = "SSID";
const char* password = "PASSWORD";
// CherryPy Server Access
const char* myServer = "192.168.2.4";
void setup() {
Serial.begin(250000);
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
int loopCount = 0;
void loop() {
String POSTrLine;
WiFiClient client;
loopCount++;
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // Toggle RED led
if(!client.connected()){
if(client.connect(myServer, 80)){
Serial.printf("New Connection to: %s\n", myServer);
}
}
else {
Serial.printf("Existing Connection to: %s\n", myServer);
}
while(client.available()){
POSTrLine = client.readStringUntil('\r');
}
client.stop();
Serial.printf("LoopCount: %u, FreeHeap: %u\n", loopCount, ESP.getFreeHeap());
}