From db725d07f5952a9c1fdab9e44f284e1108c06994 Mon Sep 17 00:00:00 2001 From: yingjiew Date: Thu, 1 Aug 2024 17:01:05 +0800 Subject: [PATCH] sm6150-common: gps: Avoid access of deprecated LocUnorderedSetMap entry When there is no client listens to some DataItemId, we will remove the map entry. Can't access the deleted entry's iterator anymore. Change-Id: Id64aadebf7362667fbcf0fd5191f888ed9241727 CRs-Fixed: 3886536 (cherry picked from commit 0049d459cc1772f328e29a4c6b6d129af132e7b8) Signed-off-by: therealmharc --- gps/utils/LocUnorderedSetMap.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gps/utils/LocUnorderedSetMap.h b/gps/utils/LocUnorderedSetMap.h index 7b25ad0..ca99320 100644 --- a/gps/utils/LocUnorderedSetMap.h +++ b/gps/utils/LocUnorderedSetMap.h @@ -141,8 +141,11 @@ public: unordered_set* goneKeys, unordered_set* goneVals) { for (auto key : keys) { auto iter = mMap.find(key); - if (iter != mMap.end() && trimOrRemove(iter, rVals, goneVals) && nullptr != goneKeys) { - goneKeys->insert(iter->first); + if (iter != mMap.end()) { + KEY goneKey = iter->first; + if (trimOrRemove(iter, rVals, goneVals) && nullptr != goneKeys) { + goneKeys->insert(goneKey); + } } } }