Skip to content

Commit

Permalink
Refs #12361. Fix wrong iterator after vector reallocation
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>
  • Loading branch information
richiware committed Aug 12, 2021
1 parent e9a70f2 commit ee88963
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/cpp/rtps/writer/LivelinessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ bool LivelinessManager::add_writer(
}
}
writers_.emplace_back(guid, kind, lease_duration);

if (!calculate_next())
{
timer_.cancel_timer();
return false;
}

// Some times the interval could be negative if a writer expired during the call to this function
// Once in this situation there is not much we can do but let asio timers expire inmediately
auto interval = timer_owner_->time - steady_clock::now();
timer_.update_interval_millisec((double)duration_cast<milliseconds>(interval).count());
timer_.restart_timer();

return true;
}

Expand Down Expand Up @@ -95,9 +108,8 @@ bool LivelinessManager::remove_writer(
}
}

if (timer_owner_ != nullptr && timer_owner_->guid == guid)
if (timer_owner_ != nullptr)
{
timer_owner_ = nullptr;
if (!calculate_next())
{
timer_.cancel_timer();
Expand Down

0 comments on commit ee88963

Please sign in to comment.