Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid using invalid iterator when erasing items using an iterator in a loop #436

Merged
merged 2 commits into from
Feb 3, 2018

Conversation

wjwwood
Copy link
Member

@wjwwood wjwwood commented Feb 2, 2018

Occurred when updating to cppcheck to 1.82 on macOS.

See: ros2/build_farmer#74 (comment)

@wjwwood wjwwood added bug Something isn't working in review Waiting for review (Kanban column) labels Feb 2, 2018
@wjwwood wjwwood self-assigned this Feb 2, 2018
@wjwwood
Copy link
Member Author

wjwwood commented Feb 2, 2018

Here's a build on the updated macOS machine:

  • macOS: Build Status

@@ -78,7 +78,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
{
for (auto it = guard_conditions_.begin(); it != guard_conditions_.end(); ++it) {
if (*it == guard_condition) {
guard_conditions_.erase(it);
it = guard_conditions_.erase(it);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? The next line breaks the loop and leaves the scope of it. I would consider the newly assigned it unused.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, I over matched it, I think I fixed it up correctly here: e0be1f6

@@ -266,11 +266,11 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
}
any_exec->callback_group = group;
any_exec->node_base = get_node_by_group(group, weak_nodes);
subscription_handles_.erase(it);
it = subscription_handles_.erase(it);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -301,11 +301,11 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
any_exec->service = service;
any_exec->callback_group = group;
any_exec->node_base = get_node_by_group(group, weak_nodes);
service_handles_.erase(it);
it = service_handles_.erase(it);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

@@ -334,11 +334,11 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
any_exec->client = client;
any_exec->callback_group = group;
any_exec->node_base = get_node_by_group(group, weak_nodes);
client_handles_.erase(it);
it = client_handles_.erase(it);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

@wjwwood
Copy link
Member Author

wjwwood commented Feb 2, 2018

Windows with upgrade and latest changes:

  • Windows: Build Status

@wjwwood wjwwood merged commit f88ade7 into master Feb 3, 2018
@wjwwood wjwwood deleted the fix_invalid_iterator_cppcheck branch February 3, 2018 00:46
@wjwwood wjwwood removed the in review Waiting for review (Kanban column) label Feb 3, 2018
@wjwwood wjwwood mentioned this pull request Feb 6, 2018
13 tasks
nnmm pushed a commit to ApexAI/rclcpp that referenced this pull request Jul 9, 2022
ros2#436)

* Revert "Changes the default 3rd party logger from rcl_logging_noop to rcl_logging_log4cxx (ros2#425)"

This reverts commit ac8ee90.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Revert "add explicit dependency on rcl_logging_log4cxx (ros2#435)"

This reverts commit 816ce67.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Add dependency on rcl_logging_noop.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants