Skip to content

Commit 446e180

Browse files
committed
Fix Coverity INVALIDATE_ITERATOR defects.
1 parent 2ef6959 commit 446e180

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

source/common/ur_singleton.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,25 @@ template <typename singleton_tn, typename key_tn> class singleton_factory_t {
7676

7777
void retain(key_tn key) {
7878
std::lock_guard<std::mutex> lk(mut);
79-
auto iter = map.find(getKey(key));
80-
assert(iter != map.end());
81-
iter->second.ref_count++;
79+
if (auto iter = map.find(getKey(key)); iter != map.end()) {
80+
iter->second.ref_count++;
81+
} else {
82+
__builtin_unreachable();
83+
}
8284
}
8385

8486
//////////////////////////////////////////////////////////////////////////
8587
/// once the key is no longer valid, release the singleton
8688
void release(key_tn key) {
8789
std::lock_guard<std::mutex> lk(mut);
88-
auto iter = map.find(getKey(key));
89-
assert(iter != map.end());
90-
if (iter->second.ref_count == 0) {
91-
map.erase(iter);
90+
if (auto iter = map.find(getKey(key)); iter != map.end()) {
91+
if (iter->second.ref_count == 0) {
92+
map.erase(iter);
93+
} else {
94+
iter->second.ref_count--;
95+
}
9296
} else {
93-
iter->second.ref_count--;
97+
__builtin_unreachable();
9498
}
9599
}
96100

0 commit comments

Comments
 (0)