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

Call Domain::removePublishe while failure occurs in create_publisher #434

Merged
merged 2 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion rmw_fastrtps_cpp/src/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ rmw_fastrtps_cpp::create_publisher(
RMW_SET_ERROR_MSG("create_publisher() could not create publisher");
return nullptr;
}
auto cleanup_publisher = rcpputils::make_scope_exit(
[info]() {
if (!Domain::removePublisher(info->publisher_)) {
RMW_SAFE_FWRITE_TO_STDERR(
"Failed to remove publisher after '"
RCUTILS_STRINGIFY(__function__) "' failed.\n");
}
});

info->publisher_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
eprosima_fastrtps_identifier, info->publisher_->getGuid());
Expand All @@ -171,7 +179,7 @@ rmw_fastrtps_cpp::create_publisher(
RMW_SET_ERROR_MSG("failed to allocate publisher");
return nullptr;
}
auto cleanup_publisher = rcpputils::make_scope_exit(
auto cleanup_rmw_publisher = rcpputils::make_scope_exit(
[rmw_publisher]() {
rmw_free(const_cast<char *>(rmw_publisher->topic_name));
rmw_publisher_free(rmw_publisher);
Expand All @@ -189,6 +197,7 @@ rmw_fastrtps_cpp::create_publisher(

rmw_publisher->options = *publisher_options;

cleanup_rmw_publisher.cancel();
cleanup_publisher.cancel();
cleanup_info.cancel();
return rmw_publisher;
Expand Down
11 changes: 10 additions & 1 deletion rmw_fastrtps_dynamic_cpp/src/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ rmw_fastrtps_dynamic_cpp::create_publisher(
RMW_SET_ERROR_MSG("create_publisher() could not create publisher");
return nullptr;
}
auto cleanup_publisher = rcpputils::make_scope_exit(
[info]() {
if (!Domain::removePublisher(info->publisher_)) {
RMW_SAFE_FWRITE_TO_STDERR(
"Failed to remove publisher after '"
RCUTILS_STRINGIFY(__function__) "' failed.\n");
}
});

info->publisher_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
eprosima_fastrtps_identifier, info->publisher_->getGuid());
Expand All @@ -186,7 +194,7 @@ rmw_fastrtps_dynamic_cpp::create_publisher(
RMW_SET_ERROR_MSG("failed to allocate publisher");
return nullptr;
}
auto cleanup_publisher = rcpputils::make_scope_exit(
auto cleanup_rmw_publisher = rcpputils::make_scope_exit(
[rmw_publisher]() {
rmw_free(const_cast<char *>(rmw_publisher->topic_name));
rmw_publisher_free(rmw_publisher);
Expand All @@ -205,6 +213,7 @@ rmw_fastrtps_dynamic_cpp::create_publisher(

rmw_publisher->options = *publisher_options;

cleanup_rmw_publisher.cancel();
cleanup_publisher.cancel();
cleanup_info.cancel();
return_type_support.cancel();
Expand Down