From fedc14bcb4ec94a878efa6200431109c936ed5e8 Mon Sep 17 00:00:00 2001 From: cottongin Date: Sat, 24 Jan 2026 23:08:35 -0500 Subject: [PATCH] fix web server OOM --- src/network/CrossPointWebServer.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/network/CrossPointWebServer.cpp b/src/network/CrossPointWebServer.cpp index 01e1e48..8f5d844 100644 --- a/src/network/CrossPointWebServer.cpp +++ b/src/network/CrossPointWebServer.cpp @@ -221,7 +221,10 @@ void CrossPointWebServer::handleClient() const { } void CrossPointWebServer::handleRoot() const { - server->send(200, "text/html", HomePageHtml); + // Use chunked sending for consistency with handleFileList (avoids String allocation) + server->setContentLength(strlen(HomePageHtml)); + server->send(200, "text/html", ""); + server->sendContent_P(HomePageHtml); Serial.printf("[%lu] [WEB] Served root page\n", millis()); } @@ -319,7 +322,14 @@ bool CrossPointWebServer::isEpubFile(const String& filename) const { return lower.endsWith(".epub"); } -void CrossPointWebServer::handleFileList() const { server->send(200, "text/html", FilesPageHtml); } +void CrossPointWebServer::handleFileList() const { + // Use chunked sending to avoid allocating 64KB+ contiguous RAM for String conversion. + // The original server->send(200, "text/html", FilesPageHtml) fails when heap is fragmented + // because it tries to create a String from the large PROGMEM array. + server->setContentLength(strlen(FilesPageHtml)); + server->send(200, "text/html", ""); + server->sendContent_P(FilesPageHtml); +} void CrossPointWebServer::handleFileListData() const { // Get current path from query string (default to root)