Skip to content

Commit

Permalink
Call Domain::removePublishe while failure occurs in create_publisher (#…
Browse files Browse the repository at this point in the history
…434)

Signed-off-by: Barry Xu <[email protected]>
  • Loading branch information
Barry-Xu-2018 authored Sep 18, 2020
1 parent 4dc7379 commit 9db729b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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

0 comments on commit 9db729b

Please sign in to comment.