diff --git a/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp b/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp index 0586bcc9..ed4a88e9 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp @@ -452,8 +452,7 @@ bool rmw_context_impl_s::create_node_data( const std::string & node_name) { std::lock_guard lock(data_->mutex_); - auto node_insertion = data_->nodes_.insert(std::make_pair(node, nullptr)); - if (!node_insertion.second) { + if (data_->nodes_.count(node) > 0) { // Node already exists. return false; } @@ -478,7 +477,10 @@ bool rmw_context_impl_s::create_node_data( return false; } - node_insertion.first->second = std::move(node_data); + auto node_insertion = data_->nodes_.insert(std::make_pair(node, std::move(node_data))); + if (!node_insertion.second) { + return false; + } return true; }