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 <jacob@openrobotics.org>
This commit is contained in:
Jacob Perron 2022-02-04 08:24:57 -08:00 committed by GitHub
parent fea44ac445
commit ef8d7532dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<char *>(node->name), allocator.state);
allocator.deallocate(const_cast<char *>(node->namespace_), allocator.state);
allocator.deallocate(node, allocator.state);
rmw_free(const_cast<char *>(node->name));
rmw_free(const_cast<char *>(node->namespace_));
rmw_node_free(const_cast<rmw_node_t *>(node));
delete node_impl;
context->impl->fini();
return result_ret;