Skip to content

Commit 4691063

Browse files
authored
Add a custom deleter when constructing rcl_service_t (#2351)
* Add a custom deleter when constructing rcl_service_t In the type description service construction, we were previously passing the shared_ptr to the rcl_service_t with the assumption that rclcpp::Service would do the clean up. This was an incorrect assumption, and so I have added a custom deleter to fini the service and delete when the shared_ptr is cleaned up. Signed-off-by: Michael Carroll <[email protected]>
1 parent f294488 commit 4691063

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

rclcpp/src/rclcpp/node_interfaces/node_type_descriptions.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,25 @@ class NodeTypeDescriptions::NodeTypeDescriptionsImpl
8585

8686
if (enabled) {
8787
auto * rcl_node = node_base->get_rcl_node_handle();
88-
auto rcl_srv = std::make_shared<rcl_service_t>();
88+
std::shared_ptr<rcl_service_t> rcl_srv(
89+
new rcl_service_t,
90+
[rcl_node, logger = this->logger_](rcl_service_t * service)
91+
{
92+
if (rcl_service_fini(service, rcl_node) != RCL_RET_OK) {
93+
RCLCPP_ERROR(
94+
logger,
95+
"Error in destruction of rcl service handle [~/get_type_description]: %s",
96+
rcl_get_error_string().str);
97+
rcl_reset_error();
98+
}
99+
delete service;
100+
});
101+
*rcl_srv = rcl_get_zero_initialized_service();
89102
rcl_ret_t rcl_ret = rcl_node_type_description_service_init(rcl_srv.get(), rcl_node);
90103

91104
if (rcl_ret != RCL_RET_OK) {
92105
RCLCPP_ERROR(
93-
logger_, "Failed to initialize ~/get_type_description_service: %s",
106+
logger_, "Failed to initialize ~/get_type_description service: %s",
94107
rcl_get_error_string().str);
95108
throw std::runtime_error(
96109
"Failed to initialize ~/get_type_description service.");

0 commit comments

Comments
 (0)