mirror of
https://github.com/esphome/esphome.git
synced 2025-11-16 14:55:50 +00:00
[light] Fix dangling reference in compute_color_mode causing memory corruption
This commit is contained in:
@@ -406,7 +406,11 @@ void LightCall::transform_parameters_() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ColorMode LightCall::compute_color_mode_() {
|
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();
|
int supported_count = supported_modes.size();
|
||||||
|
|
||||||
// Some lights don't support any color modes (e.g. monochromatic light), leave it at unknown.
|
// Some lights don't support any color modes (e.g. monochromatic light), leave it at unknown.
|
||||||
|
|||||||
Reference in New Issue
Block a user