1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-16 06:45:48 +00:00

[light] Fix dangling reference in compute_color_mode causing memory corruption

This commit is contained in:
J. Nick Koston
2025-11-12 10:33:19 -06:00
parent 56d141c741
commit c1fb8dae37

View File

@@ -406,7 +406,11 @@ void LightCall::transform_parameters_() {
}
}
ColorMode LightCall::compute_color_mode_() {
const auto &supported_modes = this->parent_->get_traits().get_supported_color_modes();
// Store traits locally to avoid dangling reference: get_traits() returns by value, so
// calling get_traits().get_supported_color_modes() would create a temporary LightTraits
// object, return a reference to its member, then destroy the temporary, leaving a dangling reference.
auto traits = this->parent_->get_traits();
const auto &supported_modes = traits.get_supported_color_modes();
int supported_count = supported_modes.size();
// Some lights don't support any color modes (e.g. monochromatic light), leave it at unknown.