Skip to content

Commit

Permalink
Fix memory leak in WebServer
Browse files Browse the repository at this point in the history
Fixes #908
  • Loading branch information
earlephilhower committed Oct 12, 2022
1 parent 98c4b92 commit 6cdebf7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ WebServer server(80);
const int led = LED_BUILTIN;

void handleRoot() {
static int cnt = 0;
digitalWrite(led, 1);
char temp[400];
int sec = millis() / 1000;
Expand All @@ -65,11 +66,13 @@ void handleRoot() {
<body>\
<h1>Hello from the Pico W!</h1>\
<p>Uptime: %02d:%02d:%02d</p>\
<p>Free Memory: %d</p>\
<p>Page Count: %d</p>\
<img src=\"/test.svg\" />\
</body>\
</html>",

hr, min % 60, sec % 60);
hr, min % 60, sec % 60, rp2040.getFreeHeap(), ++cnt);
server.send(200, "text/html", temp);
digitalWrite(led, 0);
}
Expand Down
5 changes: 4 additions & 1 deletion libraries/WebServer/src/HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ void HTTPServer::httpHandleClient() {
}

if (!keepCurrentClient) {
_currentClient = nullptr;
if (_currentClient) {
delete _currentClient;
_currentClient = nullptr;
}
_currentStatus = HC_NONE;
_currentUpload.reset();
}
Expand Down

0 comments on commit 6cdebf7

Please sign in to comment.