From f010dcd0f73a178ea36b10e503fa5ce0676c58ea Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 27 May 2016 21:08:39 +0200 Subject: [PATCH] Fix controller segfault on using fillActive function during stats update. --- src/controller/controller_statistics.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/controller/controller_statistics.cpp b/src/controller/controller_statistics.cpp index 48846053..f284290e 100644 --- a/src/controller/controller_statistics.cpp +++ b/src/controller/controller_statistics.cpp @@ -910,12 +910,15 @@ void Controller::fillActive(JSON::Value & req, JSON::Value & rep, bool onlyNow){ std::map clients; unsigned int t = Util::epoch() - STATS_DELAY; //check all sessions - if (sessions.size()){ - for (std::map::iterator it = sessions.begin(); it != sessions.end(); it++){ - if (!onlyNow || (it->second.hasDataFor(t) && it->second.isViewerOn(t))){ - streams.insert(it->first.streamName); - if (it->second.getSessType() == SESS_VIEWER){ - clients[it->first.streamName]++; + { + tthread::lock_guard guard(statsMutex); + if (sessions.size()){ + for (std::map::iterator it = sessions.begin(); it != sessions.end(); it++){ + if (!onlyNow || (it->second.hasDataFor(t) && it->second.isViewerOn(t))){ + streams.insert(it->first.streamName); + if (it->second.getSessType() == SESS_VIEWER){ + clients[it->first.streamName]++; + } } } }