From e3abe8bf7f49c38e952917dd347398b706c21cac Mon Sep 17 00:00:00 2001 From: tomoya Date: Thu, 28 May 2020 07:06:50 +0900 Subject: [PATCH] Fix lock-order-inversion (potential deadlock) (#1135) Signed-off-by: Tomoya.Fujita --- rclcpp/src/rclcpp/node_interfaces/node_graph.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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);