Skip to content

Commit

Permalink
Make sure to duplicate the enclave name. (#216)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
clalancette authored Jun 27, 2024
1 parent 5fe32d3 commit cdea502
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion rmw_zenoh_cpp/src/rmw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cdea502

Please sign in to comment.