Skip to content

Commit

Permalink
Make sure type can be unregistered successfully (#437)
Browse files Browse the repository at this point in the history
Signed-off-by: Barry Xu <[email protected]>
  • Loading branch information
Barry-Xu-2018 authored Sep 23, 2020
1 parent 9b681f8 commit 0ad6c1a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
19 changes: 11 additions & 8 deletions rmw_fastrtps_cpp/src/subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ create_subscription(
if (info->type_support_) {
_unregister_type(participant, info->type_support_);
}
if (info->subscriber_) {
if (!Domain::removeSubscriber(info->subscriber_)) {
RMW_SAFE_FWRITE_TO_STDERR(
"Failed to remove subscriber after '"
RCUTILS_STRINGIFY(__function__) "' failed.\n");
}
}
delete info->listener_;
delete info;
});
Expand Down Expand Up @@ -164,6 +157,15 @@ create_subscription(
RMW_SET_ERROR_MSG("create_subscriber() could not create subscriber");
return nullptr;
}
auto cleanup_subscription = rcpputils::make_scope_exit(
[info]() {
if (!Domain::removeSubscriber(info->subscriber_)) {
RMW_SAFE_FWRITE_TO_STDERR(
"Failed to remove subscriber after '"
RCUTILS_STRINGIFY(__function__) "' failed.\n");
}
});

info->subscription_gid_ = rmw_fastrtps_shared_cpp::create_rmw_gid(
eprosima_fastrtps_identifier, info->subscriber_->getGuid());

Expand All @@ -172,7 +174,7 @@ create_subscription(
RMW_SET_ERROR_MSG("failed to allocate subscription");
return nullptr;
}
auto cleanup_subscription = rcpputils::make_scope_exit(
auto cleanup_rmw_subscription = rcpputils::make_scope_exit(
[rmw_subscription]() {
rmw_free(const_cast<char *>(rmw_subscription->topic_name));
rmw_subscription_free(rmw_subscription);
Expand All @@ -189,6 +191,7 @@ create_subscription(
rmw_subscription->options = *subscription_options;
rmw_subscription->can_loan_messages = false;

cleanup_rmw_subscription.cancel();
cleanup_subscription.cancel();
cleanup_info.cancel();
return rmw_subscription;
Expand Down
18 changes: 10 additions & 8 deletions rmw_fastrtps_dynamic_cpp/src/subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ create_subscription(
if (info->type_support_) {
_unregister_type(participant, info->type_support_);
}
if (info->subscriber_) {
if (!Domain::removeSubscriber(info->subscriber_)) {
RMW_SAFE_FWRITE_TO_STDERR(
"Failed to remove subscriber after '"
RCUTILS_STRINGIFY(__function__) "' function failed.\n");
}
}
delete info->listener_;
delete info;
});
Expand Down Expand Up @@ -177,6 +170,14 @@ create_subscription(
RMW_SET_ERROR_MSG("create_subscriber() could not create subscriber");
return nullptr;
}
auto cleanup_subscription = rcpputils::make_scope_exit(
[info]() {
if (!Domain::removeSubscriber(info->subscriber_)) {
RMW_SAFE_FWRITE_TO_STDERR(
"Failed to remove subscriber after '"
RCUTILS_STRINGIFY(__function__) "' failed.\n");
}
});
info->subscription_gid_ = rmw_fastrtps_shared_cpp::create_rmw_gid(
eprosima_fastrtps_identifier, info->subscriber_->getGuid());

Expand All @@ -185,7 +186,7 @@ create_subscription(
RMW_SET_ERROR_MSG("failed to allocate subscription");
return nullptr;
}
auto cleanup_subscription = rcpputils::make_scope_exit(
auto cleanup_rmw_subscription = rcpputils::make_scope_exit(
[rmw_subscription]() {
rmw_free(const_cast<char *>(rmw_subscription->topic_name));
rmw_subscription_free(rmw_subscription);
Expand All @@ -204,6 +205,7 @@ create_subscription(
rmw_subscription->options = *subscription_options;
rmw_subscription->can_loan_messages = false;

cleanup_rmw_subscription.cancel();
cleanup_subscription.cancel();
cleanup_info.cancel();
return rmw_subscription;
Expand Down

0 comments on commit 0ad6c1a

Please sign in to comment.