From d769cdd30a27a5687c2bac073c1e96859bc6712c Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Fri, 29 Dec 2023 10:48:25 +0100 Subject: [PATCH] Fix: move battery's lock_guard to updateSettings() (#566) the updateSettings method is called from the web server's context and therefore accesses _upProvider in a different context than the TaskScheduler. the lock_guard needs to protect _upProvider. --- src/Battery.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Battery.cpp b/src/Battery.cpp index d68db08e..720d056f 100644 --- a/src/Battery.cpp +++ b/src/Battery.cpp @@ -26,13 +26,14 @@ void BatteryClass::init(Scheduler& scheduler) _loopTask.setCallback(std::bind(&BatteryClass::loop, this)); _loopTask.setIterations(TASK_FOREVER); _loopTask.enable(); - std::lock_guard lock(_mutex); this->updateSettings(); } void BatteryClass::updateSettings() { + std::lock_guard lock(_mutex); + if (_upProvider) { _upProvider->deinit(); _upProvider = nullptr;