Skip to content

Commit

Permalink
avoid using invalid iterator when erasing items using an iterator in …
Browse files Browse the repository at this point in the history
…a loop (ros2#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
  • Loading branch information
wjwwood committed Feb 3, 2018
1 parent 3a50368 commit f88ade7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions rclcpp/include/rclcpp/strategies/allocator_memory_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
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()) {
Expand All @@ -270,7 +270,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
return;
}
// Else, the subscription is no longer valid, remove it and continue
subscription_handles_.erase(it);
it = subscription_handles_.erase(it);
}
}

Expand All @@ -288,7 +288,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
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()) {
Expand All @@ -305,7 +305,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
return;
}
// Else, the service is no longer valid, remove it and continue
service_handles_.erase(it);
it = service_handles_.erase(it);
}
}

Expand All @@ -321,7 +321,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
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()) {
Expand All @@ -338,7 +338,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
return;
}
// Else, the service is no longer valid, remove it and continue
client_handles_.erase(it);
it = client_handles_.erase(it);
}
}

Expand Down

0 comments on commit f88ade7

Please sign in to comment.