From e19b48599c73922b7b735e4e0da5887ba55d3609 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 3 Oct 2025 16:40:10 -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 bbdb1f08a9..44ab39cc37 100644 --- a/esphome/components/web_server_idf/web_server_idf.cpp +++ b/esphome/components/web_server_idf/web_server_idf.cpp @@ -206,7 +206,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; @@ -218,10 +218,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);