Skip to content

Commit

Permalink
Address reviewer feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjcarroll committed Nov 27, 2018
1 parent 12acb2b commit 10183dd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
15 changes: 12 additions & 3 deletions rmw_fastrtps_cpp/src/rmw_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,24 @@ rmw_create_publisher(
Domain::getDefaultPublisherAttributes(publisherParam);

// TODO(karsten1987) Verify consequences for std::unique_ptr?
info = new CustomPublisherInfo();
info = new (std::nothrow) CustomPublisherInfo();
if (!info) {
RMW_SET_ERROR_MSG("failed to allocate CustomPublisherInfo");
return nullptr;
}

info->typesupport_identifier_ = type_support->typesupport_identifier;

auto callbacks = static_cast<const message_type_support_callbacks_t *>(type_support->data);
std::string type_name = _create_type_name(callbacks, "msg");
if (!Domain::getRegisteredType(participant, type_name.c_str(),
reinterpret_cast<TopicDataType **>(&info->type_support_)))
{
info->type_support_ = new MessageTypeSupport_cpp(callbacks);
info->type_support_ = new (std::nothrow) MessageTypeSupport_cpp(callbacks);
if (!info->type_support_) {
RMW_SET_ERROR_MSG("Failed to allocate MessageTypeSupport");
goto fail;
}
_register_type(participant, info->type_support_);
}

Expand Down Expand Up @@ -128,7 +137,7 @@ rmw_create_publisher(
goto fail;
}

info->listener_ = new PubListener(info);
info->listener_ = new (std::nothrow) PubListener(info);
if (!info->listener_) {
RMW_SET_ERROR_MSG("create_publisher() could not create publisher listener");
goto fail;
Expand Down
15 changes: 12 additions & 3 deletions rmw_fastrtps_cpp/src/rmw_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,24 @@ rmw_create_subscription(
// Load default XML profile.
Domain::getDefaultSubscriberAttributes(subscriberParam);

info = new CustomSubscriberInfo();
info = new (std::nothrow) CustomSubscriberInfo();
if (!info) {
RMW_SET_ERROR_MSG("failed to allocate CustomSubscriberInfo");
return nullptr;
}

info->typesupport_identifier_ = type_support->typesupport_identifier;

auto callbacks = static_cast<const message_type_support_callbacks_t *>(type_support->data);
std::string type_name = _create_type_name(callbacks, "msg");
if (!Domain::getRegisteredType(participant, type_name.c_str(),
reinterpret_cast<TopicDataType **>(&info->type_support_)))
{
info->type_support_ = new MessageTypeSupport_cpp(callbacks);
info->type_support_ = new (std::nothrow) MessageTypeSupport_cpp(callbacks);
if (!info->type_support_) {
RMW_SET_ERROR_MSG("failed to allocate MessageTypeSupport_cpp");
goto fail;
}
_register_type(participant, info->type_support_);
}

Expand All @@ -122,7 +131,7 @@ rmw_create_subscription(
goto fail;
}

info->listener_ = new SubListener(info);
info->listener_ = new (std::nothrow) SubListener(info);
if (!info->listener_) {
RMW_SET_ERROR_MSG("create_subscriber() could not create subscriber listener");
goto fail;
Expand Down
8 changes: 6 additions & 2 deletions rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ rmw_create_publisher(
Domain::getDefaultPublisherAttributes(publisherParam);

// TODO(karsten1987) Verify consequences for std::unique_ptr?
info = new CustomPublisherInfo();
info = new (std::nothrow) CustomPublisherInfo();
if (!info) {
RMW_SET_ERROR_MSG("failed to allocate CustomPublisherInfo");
return nullptr;
}
info->typesupport_identifier_ = type_support->typesupport_identifier;

std::string type_name = _create_type_name(
Expand Down Expand Up @@ -128,7 +132,7 @@ rmw_create_publisher(
goto fail;
}

info->listener_ = new PubListener(info);
info->listener_ = new (std::nothrow) PubListener(info);
if (!info->listener_) {
RMW_SET_ERROR_MSG("create_publisher() could not create publisher listener");
goto fail;
Expand Down
3 changes: 2 additions & 1 deletion rmw_fastrtps_dynamic_cpp/src/rmw_serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ rmw_serialize(
}
}

eprosima::fastcdr::FastBuffer buffer(reinterpret_cast<char *>(serialized_message->buffer),
eprosima::fastcdr::FastBuffer buffer(
reinterpret_cast<char *>(serialized_message->buffer),
data_length);
eprosima::fastcdr::Cdr ser(
buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR);
Expand Down
8 changes: 6 additions & 2 deletions rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ rmw_create_subscription(
// Load default XML profile.
Domain::getDefaultSubscriberAttributes(subscriberParam);

info = new CustomSubscriberInfo();
info = new (std::nothrow) CustomSubscriberInfo();
if (!info) {
RMW_SET_ERROR_MSG("failed to allocate CustomSubscriberInfo");
return nullptr;
}
info->typesupport_identifier_ = type_support->typesupport_identifier;

std::string type_name = _create_type_name(
Expand Down Expand Up @@ -123,7 +127,7 @@ rmw_create_subscription(
goto fail;
}

info->listener_ = new SubListener(info);
info->listener_ = new (std::nothrow) SubListener(info);
if (!info->listener_) {
RMW_SET_ERROR_MSG("create_subscriber() could not create subscriber listener");
goto fail;
Expand Down

0 comments on commit 10183dd

Please sign in to comment.