From ef8d7532dc8597bed6d431b28f55d28366eae89a Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Fri, 4 Feb 2022 08:24:57 -0800 Subject: [PATCH] Free with the same allocator in rmw_destroy_node (#355) (#369) Since rmw_allocate() was used to allocate memory, we should use rmw_free() to cleanup. Otherwise, if the user provided a custom allocator to the context we will be calling deallocate with the wrong allocator. Signed-off-by: Jacob Perron --- rmw_cyclonedds_cpp/src/rmw_node.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rmw_cyclonedds_cpp/src/rmw_node.cpp b/rmw_cyclonedds_cpp/src/rmw_node.cpp index 1d18e7e..2a8de48 100644 --- a/rmw_cyclonedds_cpp/src/rmw_node.cpp +++ b/rmw_cyclonedds_cpp/src/rmw_node.cpp @@ -1347,10 +1347,9 @@ extern "C" rmw_ret_t rmw_destroy_node(rmw_node_t * node) } rmw_context_t * context = node->context; - rcutils_allocator_t allocator = context->options.allocator; - allocator.deallocate(const_cast(node->name), allocator.state); - allocator.deallocate(const_cast(node->namespace_), allocator.state); - allocator.deallocate(node, allocator.state); + rmw_free(const_cast(node->name)); + rmw_free(const_cast(node->namespace_)); + rmw_node_free(const_cast(node)); delete node_impl; context->impl->fini(); return result_ret;