Skip to content

Commit 5c85bf8

Browse files
committed
Use count to check if node exists
Signed-off-by: Yadunund <[email protected]>
1 parent 386fbf4 commit 5c85bf8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,7 @@ bool rmw_context_impl_s::create_node_data(
393393
const std::string & node_name)
394394
{
395395
std::lock_guard<std::recursive_mutex> lock(data_->mutex_);
396-
auto node_insertion = data_->nodes_.insert(std::make_pair(node, nullptr));
397-
if (!node_insertion.second) {
396+
if (data_->nodes_.count(node) > 0) {
398397
// Node already exists.
399398
return false;
400399
}
@@ -419,7 +418,10 @@ bool rmw_context_impl_s::create_node_data(
419418
return false;
420419
}
421420

422-
node_insertion.first->second = std::move(node_data);
421+
auto node_insertion = data_->nodes_.insert(std::make_pair(node, std::move(node_data)));
422+
if (!node_insertion.second) {
423+
return false;
424+
}
423425

424426
return true;
425427
}

0 commit comments

Comments
 (0)