Skip to content

Commit

Permalink
fix possible use-after-free: unsafe shared_ptr in multithread (ros-na…
Browse files Browse the repository at this point in the history
…vigation#2510)

Co-authored-by: Kai-Tao Xie <[email protected]>
  • Loading branch information
easylyou and Kai-Tao Xie authored Aug 19, 2021
1 parent 7b29e47 commit 65e46b5
Showing 1 changed file with 4 additions and 3 deletions.
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_);
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

0 comments on commit 65e46b5

Please sign in to comment.