Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure type can be unregistered successfully #437

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 10 additions & 1 deletion rmw_fastrtps_dynamic_cpp/src/subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ create_subscription(
RMW_SET_ERROR_MSG("create_subscriber() could not create subscriber");
return nullptr;
}
auto cleanup_subscription = rcpputils::make_scope_exit(
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
[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 +193,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 +212,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