Skip to content

Commit

Permalink
Move graph guard condition destruction to rmw_context_fini.
Browse files Browse the repository at this point in the history
That's because during rmw_shutdown(), the graph guard
condition may still be in use in rwm_wait() and friends.
Fix this by moving the destruction of it later, into
rmw_context_fini.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Apr 4, 2024
1 parent eac1d84 commit 4acdb89
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions rmw_zenoh_cpp/src/rmw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,6 @@ rmw_shutdown(rmw_context_t * context)
return RMW_RET_ERROR;
}

const rcutils_allocator_t * allocator = &context->options.allocator;

RMW_TRY_DESTRUCTOR(
static_cast<GuardCondition *>(context->impl->graph_guard_condition->data)->~GuardCondition(),
GuardCondition, );
allocator->deallocate(context->impl->graph_guard_condition->data, allocator->state);

allocator->deallocate(context->impl->graph_guard_condition, allocator->state);

context->impl->is_shutdown = true;

return RMW_RET_OK;
Expand All @@ -396,10 +387,18 @@ rmw_context_fini(rmw_context_t * context)
return RMW_RET_INVALID_ARGUMENT;
}

RMW_TRY_DESTRUCTOR(context->impl->~rmw_context_impl_t(), rmw_context_impl_t, );

const rcutils_allocator_t * allocator = &context->options.allocator;

RMW_TRY_DESTRUCTOR(
static_cast<GuardCondition *>(context->impl->graph_guard_condition->data)->~GuardCondition(),
GuardCondition, );
allocator->deallocate(context->impl->graph_guard_condition->data, allocator->state);

allocator->deallocate(context->impl->graph_guard_condition, allocator->state);
context->impl->graph_guard_condition = nullptr;

RMW_TRY_DESTRUCTOR(context->impl->~rmw_context_impl_t(), rmw_context_impl_t, );

allocator->deallocate(context->impl, allocator->state);

rmw_ret_t ret = rmw_init_options_fini(&context->options);
Expand Down

0 comments on commit 4acdb89

Please sign in to comment.