From 52d680161871d007e1c6c8575a452b765fe24b8b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 14 Jul 2025 12:29:40 -1000 Subject: [PATCH] address bot comments --- .../http_request/update/http_request_update.cpp | 3 +-- esphome/components/json/json_util.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/esphome/components/http_request/update/http_request_update.cpp b/esphome/components/http_request/update/http_request_update.cpp index 5e6e7b75d9..06aa6da6a4 100644 --- a/esphome/components/http_request/update/http_request_update.cpp +++ b/esphome/components/http_request/update/http_request_update.cpp @@ -83,8 +83,7 @@ void HttpRequestUpdate::update_task(void *params) { container.reset(); // Release ownership of the container's shared_ptr valid = json::parse_json(response, [this_update](JsonObject root) -> bool { - if (!root["name"].is() || !root["version"].is() || - !root["builds"].is()) { + if (!root["name"].is() || !root["version"].is() || !root["builds"].is()) { ESP_LOGE(TAG, "Manifest does not contain required fields"); return false; } diff --git a/esphome/components/json/json_util.cpp b/esphome/components/json/json_util.cpp index 1ff5105137..5f47444582 100644 --- a/esphome/components/json/json_util.cpp +++ b/esphome/components/json/json_util.cpp @@ -1,7 +1,7 @@ #include "json_util.h" #include "esphome/core/log.h" -#include +// ArduinoJson::Allocator is included via ArduinoJson.h in json_util.h namespace esphome { namespace json { @@ -13,7 +13,11 @@ struct SpiRamAllocator : ArduinoJson::Allocator { void *allocate(size_t size) override { return this->allocator_.allocate(size); } void deallocate(void *pointer) override { - // RAMAllocator requires passing the size of the allocated space which don't know, so use free directly + // ArduinoJson's Allocator interface doesn't provide the size parameter in deallocate. + // RAMAllocator::deallocate() requires the size, which we don't have access to here. + // Since RAMAllocator internally uses malloc/free for NONE mode (PSRAM allocation), + // it's safe to use free() directly. The memory was allocated via malloc in + // RAMAllocator::allocate() when using NONE mode. free(pointer); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc) }