Skip to content

Commit

Permalink
Removed some heap interactions in rmw_serialize.cpp (#590)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Mayer <martin.mayer@gmx.de>
  • Loading branch information
WideAwakeTN authored Mar 18, 2022
1 parent bde6068 commit eb189fb
Showing 1 changed file with 5 additions and 7 deletions.
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

0 comments on commit eb189fb

Please sign in to comment.