diff --git a/rclcpp/include/rclcpp/topic_statistics/subscription_topic_statistics.hpp b/rclcpp/include/rclcpp/topic_statistics/subscription_topic_statistics.hpp index 781e2c86fc..7a6db13502 100644 --- a/rclcpp/include/rclcpp/topic_statistics/subscription_topic_statistics.hpp +++ b/rclcpp/include/rclcpp/topic_statistics/subscription_topic_statistics.hpp @@ -172,12 +172,11 @@ class SubscriptionTopicStatistics { auto received_message_age = std::make_unique(); received_message_age->Start(); - subscriber_statistics_collectors_.emplace_back(std::move(received_message_age)); - auto received_message_period = std::make_unique(); received_message_period->Start(); { std::lock_guard lock(mutex_); + subscriber_statistics_collectors_.emplace_back(std::move(received_message_age)); subscriber_statistics_collectors_.emplace_back(std::move(received_message_period)); } diff --git a/rclcpp/test/rclcpp/topic_statistics/test_subscription_topic_statistics.cpp b/rclcpp/test/rclcpp/topic_statistics/test_subscription_topic_statistics.cpp index 9166272207..a6fbbcbc74 100644 --- a/rclcpp/test/rclcpp/topic_statistics/test_subscription_topic_statistics.cpp +++ b/rclcpp/test/rclcpp/topic_statistics/test_subscription_topic_statistics.cpp @@ -343,7 +343,6 @@ TEST_F(TestSubscriptionTopicStatisticsFixture, test_receive_stats_for_message_no uint64_t message_age_count{0}; uint64_t message_period_count{0}; - std::set received_metrics; for (const auto & msg : received_messages) { if (msg.metrics_source == kMessageAgeSourceLabel) { message_age_count++;