diff --git a/src/zm_monitor.h b/src/zm_monitor.h index 8760fbf3c..f2060af33 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -341,6 +341,7 @@ class Monitor : public std::enable_shared_from_this { PullPointSubscriptionBindingProxy proxyEvent; void set_credentials(struct soap *soap); std::unordered_map alarms; + std::mutex alarms_mutex; #endif public: explicit ONVIF(Monitor *parent_); diff --git a/src/zm_monitor_onvif.cpp b/src/zm_monitor_onvif.cpp index 1cac78b3d..caa27ea3d 100644 --- a/src/zm_monitor_onvif.cpp +++ b/src/zm_monitor_onvif.cpp @@ -187,7 +187,10 @@ void Monitor::ONVIF::WaitForMessage() { // Apparently simple motion events, the value is boolean, but for people detection can be things like isMotion, isPeople if (last_value.find("false") == 0) { Info("Triggered off ONVIF"); - alarms.erase(last_topic); + { + std::unique_lock lck(alarms_mutex); + alarms.erase(last_topic); + } Debug(1, "ONVIF Alarms Empty: Alarms count is %zu, alarmed is %s, empty is %d ", alarms.size(), alarmed ? "true": "false", alarms.empty()); if (alarms.empty()) { alarmed = false; @@ -285,6 +288,7 @@ int SOAP_ENV__Fault(struct soap *soap, char *faultcode, char *faultstring, char void Monitor::ONVIF::SetNoteSet(Event::StringSet ¬eSet) { #ifdef WITH_GSOAP + std::unique_lock lck(alarms_mutex); if (alarms.empty()) return; std::string note = "";