diff --git a/rclcpp/src/rclcpp/node_interfaces/node_graph.cpp b/rclcpp/src/rclcpp/node_interfaces/node_graph.cpp index 0aa361e..4d0d46e 100644 --- a/rclcpp/src/rclcpp/node_interfaces/node_graph.cpp +++ b/rclcpp/src/rclcpp/node_interfaces/node_graph.cpp @@ -368,9 +368,11 @@ rclcpp::Event::SharedPtr NodeGraph::get_graph_event() { auto event = rclcpp::Event::make_shared(); - std::lock_guard graph_changed_lock(graph_mutex_); - graph_events_.push_back(event); - graph_users_count_++; + { + std::lock_guard graph_changed_lock(graph_mutex_); + graph_events_.push_back(event); + graph_users_count_++; + } // on first call, add node to graph_listener_ if (should_add_to_graph_listener_.exchange(false)) { graph_listener_->add_node(this);