From b12d7db5a7deea2098b298db600fd5c921f602a2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 6 Jul 2025 19:27:33 -0500 Subject: [PATCH] prevent future refactoring errors --- esphome/core/scheduler.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index f3f78d39af..79a411db92 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -99,9 +99,15 @@ class Scheduler { SchedulerItem(const SchedulerItem &) = delete; SchedulerItem &operator=(const SchedulerItem &) = delete; - // Default move operations - SchedulerItem(SchedulerItem &&) = default; - SchedulerItem &operator=(SchedulerItem &&) = default; + // Delete move operations to prevent accidental moves of SchedulerItem objects. + // This is intentional because: + // 1. SchedulerItem contains a dynamically allocated name that requires careful ownership management + // 2. The scheduler only moves unique_ptr, never SchedulerItem objects directly + // 3. Moving unique_ptr only transfers pointer ownership without moving the pointed-to object + // 4. Deleting these operations makes it explicit that SchedulerItem objects should not be moved + // 5. This prevents potential double-free bugs if the code is refactored to move SchedulerItem objects + SchedulerItem(SchedulerItem &&) = delete; + SchedulerItem &operator=(SchedulerItem &&) = delete; // Helper to get the name regardless of storage type const char *get_name() const { return name_is_dynamic ? name_.dynamic_name : name_.static_name; }