Skip to content

Commit

Permalink
Avoid using invalid std::list iterators (ros#293) + Fix accessing fre…
Browse files Browse the repository at this point in the history
…e'd resources ros#386 (ros#419)

* fix accessing freed resources (ros#386)

* Avoid using invalid std::list iterators (ros#293)

Signed-off-by: Michael Carroll <michael@openrobotics.org>

Co-authored-by: Kazunari Tanaka <tzskp1@gmail.com>
Co-authored-by: Michael Carroll <michael@openrobotics.org>
  • Loading branch information
3 people committed May 19, 2021
1 parent c561253 commit d1ec81e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tf2_ros/include/tf2_ros/message_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,17 @@ class MessageFilter : public MessageFilterBase, public message_filters::SimpleFi
{
namespace mt = message_filters::message_traits;

// find the message this request is associated with
typename L_MessageInfo::iterator msg_it = messages_.begin();
typename L_MessageInfo::iterator msg_end = messages_.end();

MEvent saved_event;
bool event_found = false;

{
// We will be accessing and mutating messages now, require unique lock
std::unique_lock<std::mutex> lock(messages_mutex_);

// find the message this request is associated with
typename L_MessageInfo::iterator msg_it = messages_.begin();
typename L_MessageInfo::iterator msg_end = messages_.end();

for (; msg_it != msg_end; ++msg_it) {
MessageInfo & info = *msg_it;
auto handle_it = std::find(info.handles.begin(), info.handles.end(), handle);
Expand All @@ -479,15 +480,14 @@ class MessageFilter : public MessageFilterBase, public message_filters::SimpleFi
saved_event = msg_it->event;
messages_.erase(msg_it);
--message_count_;
} else {
msg_it = msg_end;
}
event_found = true;
}
break;
}
}
}

if (msg_it == msg_end) {
if (!event_found) {
return;
}

Expand Down

0 comments on commit d1ec81e

Please sign in to comment.