Skip to content

Commit

Permalink
Avoid using reference after removing item on LivelinessManager (#1875)
Browse files Browse the repository at this point in the history
* Refs 11017. Avoid using reference after removing item.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs 11017. Uncrustify.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany authored Apr 23, 2021
1 parent 7b0ca25 commit c92a756
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/cpp/rtps/writer/LivelinessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ LivelinessManager::LivelinessManager(
, timer_(
service,
[this]() -> bool
{
return timer_expired();
},
{
return timer_expired();
},
0)
{
}
Expand Down Expand Up @@ -79,25 +79,19 @@ bool LivelinessManager::remove_writer(
{
if (--writer.count == 0)
{
LivelinessData::WriterStatus status = writer.status;

writers_.remove(writer);

if (callback_ != nullptr)
{
if (writer.status == LivelinessData::WriterStatus::ALIVE)
if (status == LivelinessData::WriterStatus::ALIVE)
{
callback_(writer.guid,
writer.kind,
writer.lease_duration,
-1,
0);
callback_(guid, kind, lease_duration, -1, 0);
}
else if (writer.status == LivelinessData::WriterStatus::NOT_ALIVE)
else if (status == LivelinessData::WriterStatus::NOT_ALIVE)
{
callback_(writer.guid,
writer.kind,
writer.lease_duration,
0,
-1);
callback_(guid, kind, lease_duration, 0, -1);
}
}

Expand Down Expand Up @@ -228,7 +222,7 @@ bool LivelinessManager::calculate_next()

bool any_alive = false;

for (LivelinessDataIterator it=writers_.begin(); it!=writers_.end(); ++it)
for (LivelinessDataIterator it = writers_.begin(); it != writers_.end(); ++it)
{
if (it->status == LivelinessData::WriterStatus::ALIVE)
{
Expand Down Expand Up @@ -281,7 +275,7 @@ bool LivelinessManager::find_writer(
const Duration_t& lease_duration,
ResourceLimitedVector<LivelinessData>::iterator* wit_out)
{
for (LivelinessDataIterator it=writers_.begin(); it!=writers_.end(); ++it)
for (LivelinessDataIterator it = writers_.begin(); it != writers_.end(); ++it)
{
if (it->guid == guid &&
it->kind == kind &&
Expand Down Expand Up @@ -341,6 +335,6 @@ const ResourceLimitedVector<LivelinessData>& LivelinessManager::get_liveliness_d
return writers_;
}

}
}
}
} // namespace rtps
} // namespace fastrtps
} // namespace eprosima

0 comments on commit c92a756

Please sign in to comment.