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

Avoid using reference after removing item on LivelinessManager [11019] #1873

Merged
merged 2 commits into from
Apr 23, 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
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