Skip to content

Commit

Permalink
Merge pull request #10 from gerkey/fix_alloc
Browse files Browse the repository at this point in the history
Match alloc and free calls
  • Loading branch information
wjwwood committed Dec 30, 2015
2 parents 2f65836 + 95bda48 commit e04a32d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions rmw_fastrtps_cpp/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ extern "C"
return NULL;
}

rmw_node_t * node_handle = rmw_node_allocate();
rmw_node_t * node_handle =
static_cast<rmw_node_t *>(malloc(sizeof(rmw_node_t)));
if (!node_handle) {
RMW_SET_ERROR_MSG("failed to allocate rmw_node_t");
return NULL;
Expand All @@ -289,7 +290,7 @@ extern "C"
node_handle->data = participant;

node_handle->name =
reinterpret_cast<const char *>(malloc(sizeof(char) * strlen(name) + 1));
static_cast<const char *>(malloc(sizeof(char) * strlen(name) + 1));
if (!node_handle->name) {
RMW_SET_ERROR_MSG("failed to allocate memory");
return NULL;
Expand Down Expand Up @@ -321,10 +322,10 @@ extern "C"

node->data = nullptr;
if (node->name) {
delete(const_cast<char *>(node->name));
free(const_cast<char *>(node->name));
node->name = nullptr;
}
delete(node);
free(static_cast<void*>(node));

return RMW_RET_OK;
}
Expand Down

0 comments on commit e04a32d

Please sign in to comment.