Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

update to support node namespaces in rmw API #220

Merged
merged 6 commits into from
Apr 8, 2017
Merged

Conversation

wjwwood
Copy link
Member

@wjwwood wjwwood commented Mar 29, 2017

Connects to ros2/rmw#95

@wjwwood wjwwood added enhancement New feature or request in progress Actively being worked on (Kanban column) labels Mar 29, 2017
@wjwwood wjwwood self-assigned this Mar 29, 2017
node_handle->name_space =
reinterpret_cast<const char *>(rmw_allocate(sizeof(char) * strlen(name_space) + 1));
if (!node_handle->name_space) {
RMW_SET_ERROR_MSG("failed to allocate memory for node name");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-n-paste error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks fixed in 930df8f.

@wjwwood wjwwood added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Mar 30, 2017
if (!participant_qos.participant_name.name) {
RMW_SET_ERROR_MSG("failed to allocate memory");
return NULL;
}
participant_qos.participant_name.name = strdup(name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that a potential memory leak here? We call rmw_allocate beforehand and then in line 330 strdup allocates again memory for the string internally.
Sorry for comment on this line, it's technically not part of the PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes... I was just adding the check that I thought was missing. But the malloc looks completely unnecessary and leaked because we use strdup there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it in this branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 27ffa13 for my guess at a fix, I'm still waiting for it to rebuild so I can check for double free's.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man, git blame, that beast 😆

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to remove the extra free. DDS appears to free this for us, because I get this on exit if I leave the free in:

[D0087|DELETE Sub]RTIOsapiHeap_freeBufferAligned:inconsistent free/alloc: block id 0X1 being freed with "RTIOsapiHeap_freeBufferAligned" and was allocated with "RTIOsapiHeap_unknownFunction"
talker(63898,0x7fff72c12000) malloc: *** error for object 0x7fc288c17cc0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

See: 44fb031

RMW_SET_ERROR_MSG("failed to allocate memory for node namespace");
goto fail;
}
memcpy(const_cast<char *>(node_handle->namespace_), namespace_, strlen(namespace_) + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is link to the previous comment, where I believe that memcpy is the right approach here and strdup isn't.

@@ -555,6 +574,8 @@ destroy_node(const char * implementation_identifier, rmw_node_t * node)
node->data = nullptr;
rmw_free(const_cast<char *>(node->name));
node->name = nullptr;
rmw_free(const_cast<char *>(node->namespace_));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't look up the complete node struct here, but what's the difference between the node and the node_handle is this context?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node_handle is just the variable name in the create_node function. In this function, destroy_node that same object is passed in as node rather than node_handle. At least that's how I read the code.

@wjwwood wjwwood merged commit c70f9f7 into master Apr 8, 2017
@wjwwood wjwwood deleted the node_namespace branch April 8, 2017 09:05
@wjwwood wjwwood removed the in review Waiting for review (Kanban column) label Apr 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants