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

Removed some heap interactions in rmw_serialize.cpp #590

Merged
merged 1 commit into from
Mar 18, 2022
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
12 changes: 5 additions & 7 deletions rmw_fastrtps_cpp/src/rmw_serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ rmw_serialize(
}

auto callbacks = static_cast<const message_type_support_callbacks_t *>(ts->data);
auto tss = new MessageTypeSupport_cpp(callbacks);
auto data_length = tss->getEstimatedSerializedSize(ros_message, callbacks);
auto tss = MessageTypeSupport_cpp(callbacks);
auto data_length = tss.getEstimatedSerializedSize(ros_message, callbacks);
if (serialized_message->buffer_capacity < data_length) {
if (rmw_serialized_message_resize(serialized_message, data_length) != RMW_RET_OK) {
RMW_SET_ERROR_MSG("unable to dynamically resize serialized message");
Expand All @@ -54,10 +54,9 @@ rmw_serialize(
eprosima::fastcdr::Cdr ser(
buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR);

auto ret = tss->serializeROSmessage(ros_message, ser, callbacks);
auto ret = tss.serializeROSmessage(ros_message, ser, callbacks);
serialized_message->buffer_length = data_length;
serialized_message->buffer_capacity = data_length;
delete tss;
return ret == true ? RMW_RET_OK : RMW_RET_ERROR;
}

Expand All @@ -79,14 +78,13 @@ rmw_deserialize(
}

auto callbacks = static_cast<const message_type_support_callbacks_t *>(ts->data);
auto tss = new MessageTypeSupport_cpp(callbacks);
auto tss = MessageTypeSupport_cpp(callbacks);
eprosima::fastcdr::FastBuffer buffer(
reinterpret_cast<char *>(serialized_message->buffer), serialized_message->buffer_length);
eprosima::fastcdr::Cdr deser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);

auto ret = tss->deserializeROSmessage(deser, ros_message, callbacks);
delete tss;
auto ret = tss.deserializeROSmessage(deser, ros_message, callbacks);
return ret == true ? RMW_RET_OK : RMW_RET_ERROR;
}

Expand Down