Skip to content

Commit

Permalink
Change the order of destruction to prevent use of released objects (#…
Browse files Browse the repository at this point in the history
…2714)

* Change destruction order to prevent using released objects

Signed-off-by: Artem Shumov <agshumov@sberautotech.ru>

* Refs #14737: Disable periodic HB event before deinit

Signed-off-by: Eduardo Ponz <eduardoponz@eprosima.com>

Co-authored-by: Eduardo Ponz <eduardoponz@eprosima.com>
(cherry picked from commit afd8e1f)

Co-authored-by: Artem Shumov <shumov-ag@yandex.ru>
  • Loading branch information
mergify[bot] and shumov-ag authored Jun 3, 2022
1 parent 61544a1 commit a9f4841
Showing 1 changed file with 10 additions and 10 deletions.
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

0 comments on commit a9f4841

Please sign in to comment.