From 201605b6315d5474e458c655eb4fb9952151b732 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 20 Nov 2023 14:43:08 +0100 Subject: [PATCH] Fix a bug in concurrent modif of a collection that was revealed by GLIBCXX_DEBUG Thanks agiersch for the diagnostic and patch. I tested it effective. --- src/plugins/battery.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/plugins/battery.cpp b/src/plugins/battery.cpp index 9639bf67e5..c682e178ac 100644 --- a/src/plugins/battery.cpp +++ b/src/plugins/battery.cpp @@ -208,18 +208,16 @@ void Battery::update() energy_stored_j_ = std::min(energy_stored_j_, 3600 * capacity_wh_); last_updated_ = now; - std::vector> to_delete = {}; - for (auto handler : handlers_) { + auto handlers_2 = handlers_; + for (auto handler : handlers_2) { if (abs(handler->time_delta_ - time_delta_s) < 0.000000001) { handler->callback_(); if (handler->persistancy_ == Handler::Persistancy::PERSISTANT) handler->time_delta_ = -1; else - to_delete.push_back(handler); + delete_handler(handler); } } - for (auto handler : to_delete) - delete_handler(handler); }); } -- 2.20.1