From ab395fda568a8a8a5ec59a7ff02baea019d77ec0 Mon Sep 17 00:00:00 2001 From: Infrasonics Date: Tue, 17 Nov 2020 23:22:43 +0100 Subject: [PATCH] Fix issue #1 (#2) Makes the iteration to clean old ack data in ClockServer::updateEntry dependent on previous entry deletion. Co-authored-by: Fabian Dreer --- ClockKit/ClockServer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ClockKit/ClockServer.cpp b/ClockKit/ClockServer.cpp index cc9200c..e8f596a 100644 --- a/ClockKit/ClockServer.cpp +++ b/ClockKit/ClockServer.cpp @@ -104,11 +104,14 @@ void ClockServer::updateEntry(string addr, int offset, int rtt) map::iterator it; // purge old entries - for(it = ackData_.begin(); it != ackData_.end(); it++) + for(it = ackData_.begin(); it != ackData_.end();) { timestamp_t entryTime = (it->second).time; - if (now - entryTime > SYSTEM_STATE_PURGE_TIME) - ackData_.erase(it); + if (now - entryTime > SYSTEM_STATE_PURGE_TIME) { + it = ackData_.erase(it); + } else { + ++it; + } } // calculate maximum offset