Skip to content

Commit

Permalink
Avoid memory leak; setName makes its own copy of the string.
Browse files Browse the repository at this point in the history
  • Loading branch information
codebot committed Apr 1, 2016
1 parent b19a0b4 commit 8e501cd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rmw_fastrtps_cpp/src/MessageTypeSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ MessageTypeSupport::MessageTypeSupport(const rosidl_typesupport_introspection_cp
typeTooLarge_ = true;

std::string name = std::string(members->package_name_) + "::msg::dds_::" + members->message_name_ + "_";
setName(strdup(name.c_str()));
setName(name.c_str());

if(members->member_count_ != 0)
m_typeSize = calculateMaxSerializedSize(members, 0);
Expand Down
1 change: 1 addition & 0 deletions rmw_fastrtps_cpp/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ extern "C"
static_cast<const char *>(malloc(sizeof(char) * strlen(name) + 1));
if (!node_handle->name) {
RMW_SET_ERROR_MSG("failed to allocate memory");
free(node_handle);
return NULL;
}
memcpy(const_cast<char *>(node_handle->name), name, strlen(name) + 1);
Expand Down

0 comments on commit 8e501cd

Please sign in to comment.