From cdea502d5537f8ff22ae854568f59ce3bb09543b Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Thu, 27 Jun 2024 14:27:02 -0400 Subject: [PATCH] Make sure to duplicate the enclave name. (#216) It is not enough for us to take a pointer; the option structure may go away after this call. Instead, make a duplicate of the enclave name. Signed-off-by: Chris Lalancette --- rmw_zenoh_cpp/src/rmw_init.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rmw_zenoh_cpp/src/rmw_init.cpp b/rmw_zenoh_cpp/src/rmw_init.cpp index 77109da4..04126ece 100644 --- a/rmw_zenoh_cpp/src/rmw_init.cpp +++ b/rmw_zenoh_cpp/src/rmw_init.cpp @@ -153,7 +153,15 @@ rmw_init(const rmw_init_options_t * options, rmw_context_t * context) }); // Set the enclave. - context->impl->enclave = options->enclave; + context->impl->enclave = rcutils_strdup(options->enclave, *allocator); + RMW_CHECK_FOR_NULL_WITH_MSG( + context->impl->enclave, + "failed to allocate enclave", + return RMW_RET_BAD_ALLOC); + auto free_enclave = rcpputils::make_scope_exit( + [context, allocator]() { + allocator->deallocate(context->impl->enclave, allocator->state); + }); // Initialize context's implementation context->impl->is_shutdown = false; @@ -363,6 +371,7 @@ rmw_init(const rmw_init_options_t * options, rmw_context_t * context) impl_destructor.cancel(); free_guard_condition_data.cancel(); free_guard_condition.cancel(); + free_enclave.cancel(); free_options.cancel(); impl_destructor.cancel(); free_impl.cancel(); @@ -434,6 +443,8 @@ rmw_context_fini(rmw_context_t * context) allocator->deallocate(context->impl->graph_guard_condition, allocator->state); context->impl->graph_guard_condition = nullptr; + allocator->deallocate(context->impl->enclave, allocator->state); + RMW_TRY_DESTRUCTOR(context->impl->~rmw_context_impl_t(), rmw_context_impl_t *, ); allocator->deallocate(context->impl, allocator->state);