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

Improve __rmw_create_wait_set() implementation. #427

Merged
merged 2 commits into from
Aug 28, 2020
Merged
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
22 changes: 12 additions & 10 deletions rmw_fastrtps_shared_cpp/src/rmw_wait_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,34 @@ __rmw_create_wait_set(const char * identifier, rmw_context_t * context, size_t m
return nullptr);

(void)max_conditions;
rmw_wait_set_t * wait_set = rmw_wait_set_allocate();
CustomWaitsetInfo * wait_set_info = nullptr;

// From here onward, error results in unrolling in the goto fail block.
CustomWaitsetInfo * wait_set_info = nullptr;
rmw_wait_set_t * wait_set = rmw_wait_set_allocate();
if (!wait_set) {
RMW_SET_ERROR_MSG("failed to allocate wait set");
goto fail;
}
wait_set->implementation_identifier = identifier;
wait_set->data = rmw_allocate(sizeof(CustomWaitsetInfo));
// This should default-construct the fields of CustomWaitsetInfo
wait_set_info = static_cast<CustomWaitsetInfo *>(wait_set->data);
// cppcheck-suppress syntaxError
RMW_TRY_PLACEMENT_NEW(wait_set_info, wait_set_info, goto fail, CustomWaitsetInfo, )
if (!wait_set_info) {
RMW_SET_ERROR_MSG("failed to construct wait set info struct");
if (!wait_set->data) {
RMW_SET_ERROR_MSG("failed to allocate wait set info");
goto fail;
}
// This should default-construct the fields of CustomWaitsetInfo
RMW_TRY_PLACEMENT_NEW(
wait_set_info,
wait_set->data,
goto fail,
// cppcheck-suppress syntaxError
CustomWaitsetInfo, );
(void) wait_set_info;

return wait_set;

fail:
if (wait_set) {
if (wait_set->data) {
RMW_TRY_DESTRUCTOR_FROM_WITHIN_FAILURE(
wait_set_info->~CustomWaitsetInfo(), wait_set_info)
rmw_free(wait_set->data);
}
rmw_wait_set_free(wait_set);
Expand Down