From: Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics
Date: Fri, 5 Jul 2024 05:27:31 +0000 (+0200)
Subject: [Iotcon] Prevent concurent access to map
X-Git-Tag: accepted/tizen/unified/20240705.163311^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8eea78cb72e11bd4a43ed03d7b5b3b8c463f2c4a;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Iotcon] Prevent concurent access to map
Iotcon service seems to call Store/RemoveRemoteResource from different
threads. It was found a cause of crash on TV (KONA DF240619-01092) this
commit should prevent crash in the future.
[Verification] Iotcon TCT passrate 100% (PontusM)
Change-Id: I741d0d06a4a7918cf05cd590df68e8de9e78bc5f
---
diff --git a/src/iotcon/iotcon_client_manager.cc b/src/iotcon/iotcon_client_manager.cc
index e34193f3..5920e7aa 100644
--- a/src/iotcon/iotcon_client_manager.cc
+++ b/src/iotcon/iotcon_client_manager.cc
@@ -138,25 +138,31 @@ common::TizenResult IotconClientManager::RemovePresenceEventListener(long long i
picojson::value IotconClientManager::StoreRemoteResource(FoundRemoteInfoPtr ptr) {
ScopeLogger();
- if (0 == ptr->id) {
- LoggerD("New remote, needed to be added to map");
- ptr->id = GetRemoteNextId();
- remotes_map_.insert(std::make_pair(ptr->id, ptr));
- } else {
- LoggerD("Remote is already stored, just increase ref_count");
- ptr->ref_count++;
+ {
+ std::lock_guard guard(remotes_map_mutex_);
+ if (0 == ptr->id) {
+ LoggerD("New remote, needed to be added to map");
+ ptr->id = GetRemoteNextId();
+ remotes_map_.insert(std::make_pair(ptr->id, ptr));
+ } else {
+ LoggerD("Remote is already stored, just increase ref_count");
+ ptr->ref_count++;
+ }
}
return PrepareManageIdAnswer(true, ptr->id);
}
picojson::value IotconClientManager::RemoveRemoteResource(FoundRemoteInfoPtr ptr) {
ScopeLogger();
- ptr->ref_count--;
- if (ptr->ref_count <= 0) {
- LoggerD("Handle not needed anymore, removing from map");
- Remove(ptr->id);
- remotes_map_.erase(ptr->id);
- return PrepareManageIdAnswer(false);
+ {
+ std::lock_guard guard(remotes_map_mutex_);
+ ptr->ref_count--;
+ if (ptr->ref_count <= 0) {
+ LoggerD("Handle not needed anymore, removing from map");
+ Remove(ptr->id);
+ remotes_map_.erase(ptr->id);
+ return PrepareManageIdAnswer(false);
+ }
}
return PrepareManageIdAnswer(true, ptr->id);
}
diff --git a/src/iotcon/iotcon_client_manager.h b/src/iotcon/iotcon_client_manager.h
index f3fccefc..4302fb18 100644
--- a/src/iotcon/iotcon_client_manager.h
+++ b/src/iotcon/iotcon_client_manager.h
@@ -59,6 +59,7 @@ class IotconClientManager {
PresenceMap presence_map_;
FoundRemotesMap remotes_map_;
+ std::mutex remotes_map_mutex_;
IdVector ids_;
};