From f88ade7a2a5f9bd2a177054cf4f297286f631057 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Fri, 2 Feb 2018 16:46:24 -0800 Subject: [PATCH] avoid using invalid iterator when erasing items using an iterator in a loop (#436) * avoid using invalid iterator when erasing items using an iterator in a loop * do not overwrite iterator in cases where it will be unused --- .../rclcpp/strategies/allocator_memory_strategy.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rclcpp/include/rclcpp/strategies/allocator_memory_strategy.hpp b/rclcpp/include/rclcpp/strategies/allocator_memory_strategy.hpp index cdbab7c..56ac07a 100644 --- a/rclcpp/include/rclcpp/strategies/allocator_memory_strategy.hpp +++ b/rclcpp/include/rclcpp/strategies/allocator_memory_strategy.hpp @@ -249,7 +249,7 @@ public: if (!group) { // Group was not found, meaning the subscription is not valid... // Remove it from the ready list and continue looking - subscription_handles_.erase(it); + it = subscription_handles_.erase(it); continue; } if (!group->can_be_taken_from().load()) { @@ -270,7 +270,7 @@ public: return; } // Else, the subscription is no longer valid, remove it and continue - subscription_handles_.erase(it); + it = subscription_handles_.erase(it); } } @@ -288,7 +288,7 @@ public: if (!group) { // Group was not found, meaning the service is not valid... // Remove it from the ready list and continue looking - service_handles_.erase(it); + it = service_handles_.erase(it); continue; } if (!group->can_be_taken_from().load()) { @@ -305,7 +305,7 @@ public: return; } // Else, the service is no longer valid, remove it and continue - service_handles_.erase(it); + it = service_handles_.erase(it); } } @@ -321,7 +321,7 @@ public: if (!group) { // Group was not found, meaning the service is not valid... // Remove it from the ready list and continue looking - client_handles_.erase(it); + it = client_handles_.erase(it); continue; } if (!group->can_be_taken_from().load()) { @@ -338,7 +338,7 @@ public: return; } // Else, the service is no longer valid, remove it and continue - client_handles_.erase(it); + it = client_handles_.erase(it); } }