From 994659219677252c9a249d5fab9d560792191bca Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 11 Jul 2025 22:01:39 +1200 Subject: [PATCH] [scheduler] Fix crash with defer --- esphome/core/scheduler.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index d3da003a88..8649995c56 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -1,13 +1,13 @@ #include "scheduler.h" +#include +#include +#include #include "application.h" #include "esphome/core/defines.h" #include "esphome/core/hal.h" #include "esphome/core/helpers.h" #include "esphome/core/log.h" -#include -#include -#include namespace esphome { @@ -86,8 +86,10 @@ void HOT Scheduler::set_timer_common_(Component *component, SchedulerItem::Type // ESP8266 and RP2040 are excluded because they don't need thread-safe defer handling if (delay == 0 && type == SchedulerItem::TIMEOUT) { // Put in defer queue for guaranteed FIFO execution - LockGuard guard{this->lock_}; - this->cancel_item_locked_(component, name_cstr, type); + if (is_name_valid_(name_cstr)) { + LockGuard guard{this->lock_}; + this->cancel_item_locked_(component, name_cstr, type); + } this->defer_queue_.push_back(std::move(item)); return; }