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

fix possible use-after-free: unsafe shared_ptr in multithread #2510

Merged
merged 2 commits into from
Aug 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions nav2_costmap_2d/src/footprint_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ FootprintSubscriber::getFootprint(
return false;
}

auto current_footprint = std::atomic_load(&footprint_);
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
footprint = toPointVector(
std::make_shared<geometry_msgs::msg::Polygon>(footprint_->polygon));
auto & footprint_stamp = footprint_->header.stamp;
std::make_shared<geometry_msgs::msg::Polygon>(current_footprint->polygon));
auto & footprint_stamp = current_footprint->header.stamp;

if (stamp - footprint_stamp > valid_footprint_timeout) {
return false;
Expand Down Expand Up @@ -89,7 +90,7 @@ FootprintSubscriber::getFootprint(
void
FootprintSubscriber::footprint_callback(const geometry_msgs::msg::PolygonStamped::SharedPtr msg)
{
footprint_ = msg;
std::atomic_store(&footprint_, msg);
if (!footprint_received_) {
footprint_received_ = true;
}
Expand Down