* Fix memory leak in rcl_subscription_init()/rcl_publisher_init() (#794) * Fix memory leak in rcl_subscription_init()/rcl_publisher_init() In rcl_subscription_init(), while rmw_subscription_get_actual_qos() return failure, created rmw subscription handle isn't freed. In rcl_publisher_init(), while rmw_publisher_get_actual_qos() return failure, created rmw publisher handle isn't freed. Signed-off-by: Barry Xu <barry.xu@sony.com> * Remove codes on the cascading errors. Signed-off-by: Barry Xu <barry.xu@sony.com> * Change code style Signed-off-by: Barry Xu <barry.xu@sony.com> * Output error message to stderr Signed-off-by: Barry Xu <barry.xu@sony.com> * Remove format string This version of the macro is not available in Foxy. Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Print new line Signed-off-by: Jacob Perron <jacob@openrobotics.org> Co-authored-by: Barry Xu <barry.xu@sony.com>
This commit is contained in:
parent
6ec0c6cfa2
commit
76a706db9b
2 changed files with 18 additions and 0 deletions
|
@ -197,6 +197,15 @@ rcl_publisher_init(
|
|||
goto cleanup;
|
||||
fail:
|
||||
if (publisher->impl) {
|
||||
if (publisher->impl->rmw_handle) {
|
||||
rmw_ret_t rmw_fail_ret = rmw_destroy_publisher(
|
||||
rcl_node_get_rmw_handle(node), publisher->impl->rmw_handle);
|
||||
if (RMW_RET_OK != rmw_fail_ret) {
|
||||
RCUTILS_SAFE_FWRITE_TO_STDERR(rmw_get_error_string().str);
|
||||
RCUTILS_SAFE_FWRITE_TO_STDERR("\n");
|
||||
}
|
||||
}
|
||||
|
||||
allocator->deallocate(publisher->impl, allocator->state);
|
||||
publisher->impl = NULL;
|
||||
}
|
||||
|
|
|
@ -193,6 +193,15 @@ rcl_subscription_init(
|
|||
goto cleanup;
|
||||
fail:
|
||||
if (subscription->impl) {
|
||||
if (subscription->impl->rmw_handle) {
|
||||
rmw_ret_t rmw_fail_ret = rmw_destroy_subscription(
|
||||
rcl_node_get_rmw_handle(node), subscription->impl->rmw_handle);
|
||||
if (RMW_RET_OK != rmw_fail_ret) {
|
||||
RCUTILS_SAFE_FWRITE_TO_STDERR(rmw_get_error_string().str);
|
||||
RCUTILS_SAFE_FWRITE_TO_STDERR("\n");
|
||||
}
|
||||
}
|
||||
|
||||
allocator->deallocate(subscription->impl, allocator->state);
|
||||
}
|
||||
ret = fail_ret;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue