From 4acdb89487252ad71b29a7925473c105f04c24fb Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Thu, 4 Apr 2024 15:38:17 -0400 Subject: [PATCH] Move graph guard condition destruction to rmw_context_fini. 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 --- rmw_zenoh_cpp/src/rmw_init.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/rmw_zenoh_cpp/src/rmw_init.cpp b/rmw_zenoh_cpp/src/rmw_init.cpp index b90cdf61..5a0cb19c 100644 --- a/rmw_zenoh_cpp/src/rmw_init.cpp +++ b/rmw_zenoh_cpp/src/rmw_init.cpp @@ -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(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; @@ -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(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);