From a8d120ca094d2c77a512c50089146837f8b74bd5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 3 Oct 2025 16:36:43 -0500 Subject: [PATCH] fix dangling pointer --- esphome/components/web_server_idf/web_server_idf.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/esphome/components/web_server_idf/web_server_idf.cpp b/esphome/components/web_server_idf/web_server_idf.cpp index 39dbea4ba1..063d6f204c 100644 --- a/esphome/components/web_server_idf/web_server_idf.cpp +++ b/esphome/components/web_server_idf/web_server_idf.cpp @@ -232,7 +232,7 @@ void AsyncWebServerRequest::redirect(const std::string &url) { void AsyncWebServerRequest::init_response_(AsyncWebServerResponse *rsp, int code, const char *content_type) { // Set status code - use constants for common codes to avoid string allocation - const char *status; + const char *status = nullptr; switch (code) { case 200: status = HTTPD_200; @@ -244,10 +244,9 @@ void AsyncWebServerRequest::init_response_(AsyncWebServerResponse *rsp, int code status = HTTPD_409; break; default: - status = to_string(code).c_str(); break; } - httpd_resp_set_status(*this, status); + httpd_resp_set_status(*this, status == nullptr ? to_string(code).c_str() : status); if (content_type && *content_type) { httpd_resp_set_type(*this, content_type);