[cst816][http_request] Fix status_set_error() dangling pointer bugs (#12033)

This commit is contained in:
J. Nick Koston
2025-11-21 06:41:48 -06:00
committed by Jonathan Swoboda
parent d698083ede
commit f8efefffaa
2 changed files with 8 additions and 7 deletions

View File

@@ -19,7 +19,8 @@ void CST816Touchscreen::continue_setup_() {
case CST816T_CHIP_ID: case CST816T_CHIP_ID:
break; break;
default: default:
this->status_set_error(str_sprintf("Unknown chip ID 0x%02X", this->chip_id_).c_str()); ESP_LOGE(TAG, "Unknown chip ID: 0x%02X", this->chip_id_);
this->status_set_error("Unknown chip ID");
this->mark_failed(); this->mark_failed();
return; return;
} }

View File

@@ -49,18 +49,18 @@ void HttpRequestUpdate::update_task(void *params) {
auto container = this_update->request_parent_->get(this_update->source_url_); auto container = this_update->request_parent_->get(this_update->source_url_);
if (container == nullptr || container->status_code != HTTP_STATUS_OK) { if (container == nullptr || container->status_code != HTTP_STATUS_OK) {
std::string msg = str_sprintf("Failed to fetch manifest from %s", this_update->source_url_.c_str()); ESP_LOGE(TAG, "Failed to fetch manifest from %s", this_update->source_url_.c_str());
// Defer to main loop to avoid race condition on component_state_ read-modify-write // Defer to main loop to avoid race condition on component_state_ read-modify-write
this_update->defer([this_update, msg]() { this_update->status_set_error(msg.c_str()); }); this_update->defer([this_update]() { this_update->status_set_error("Failed to fetch manifest"); });
UPDATE_RETURN; UPDATE_RETURN;
} }
RAMAllocator<uint8_t> allocator; RAMAllocator<uint8_t> allocator;
uint8_t *data = allocator.allocate(container->content_length); uint8_t *data = allocator.allocate(container->content_length);
if (data == nullptr) { if (data == nullptr) {
std::string msg = str_sprintf("Failed to allocate %zu bytes for manifest", container->content_length); ESP_LOGE(TAG, "Failed to allocate %zu bytes for manifest", container->content_length);
// Defer to main loop to avoid race condition on component_state_ read-modify-write // Defer to main loop to avoid race condition on component_state_ read-modify-write
this_update->defer([this_update, msg]() { this_update->status_set_error(msg.c_str()); }); this_update->defer([this_update]() { this_update->status_set_error("Failed to allocate memory for manifest"); });
container->end(); container->end();
UPDATE_RETURN; UPDATE_RETURN;
} }
@@ -121,9 +121,9 @@ void HttpRequestUpdate::update_task(void *params) {
} }
if (!valid) { if (!valid) {
std::string msg = str_sprintf("Failed to parse JSON from %s", this_update->source_url_.c_str()); ESP_LOGE(TAG, "Failed to parse JSON from %s", this_update->source_url_.c_str());
// Defer to main loop to avoid race condition on component_state_ read-modify-write // Defer to main loop to avoid race condition on component_state_ read-modify-write
this_update->defer([this_update, msg]() { this_update->status_set_error(msg.c_str()); }); this_update->defer([this_update]() { this_update->status_set_error("Failed to parse manifest JSON"); });
UPDATE_RETURN; UPDATE_RETURN;
} }