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

Change the order of destruction to prevent use of released objects [14737] (backport #2642) #2714

Merged
merged 1 commit into from
Jun 3, 2022
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
20 changes: 10 additions & 10 deletions src/cpp/rtps/writer/StatefulWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ StatefulWriter::~StatefulWriter()
{
logInfo(RTPS_WRITER, "StatefulWriter destructor");

// This must be the first action, because free CacheChange_t from async thread.
deinit();

// Disable timed events, because their callbacks use cache changes
if (disable_positive_acks_)
{
delete(ack_event_);
Expand All @@ -327,6 +325,15 @@ StatefulWriter::~StatefulWriter()
nack_response_event_ = nullptr;
}

if (periodic_hb_event_ != nullptr)
{
delete(periodic_hb_event_);
periodic_hb_event_ = nullptr;
}

// This must be the next action, as it frees CacheChange_t from the async thread.
deinit();

// Stop all active proxies and pass them to the pool
{
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
Expand All @@ -353,13 +360,6 @@ StatefulWriter::~StatefulWriter()
}
}

// Destroy heartbeat event
if (periodic_hb_event_ != nullptr)
{
delete(periodic_hb_event_);
periodic_hb_event_ = nullptr;
}

// Delete all proxies in the pool
for (ReaderProxy* remote_reader : matched_readers_pool_)
{
Expand Down