From 890f14860dac6929f54b3e0f4f9680d3f5930585 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 21 Oct 2024 15:18:05 -0400 Subject: [PATCH] We need a lock around accessing the alarms map, because the onvif thread may clear an item while we are accessing it. --- src/zm_monitor.h | 1 + src/zm_monitor_onvif.cpp | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) 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 = "";