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

Out-of-scope memory use and memory leak issue #172

Merged
merged 2 commits into from
Nov 6, 2017

Conversation

gaoethan
Copy link
Contributor

@gaoethan gaoethan commented Nov 1, 2017

temp going out of scope leaks the storage it points to
resource leak from local_namespace_

Signed-off-by: Ethan Gao ethan.gao@linux.intel.com

temp going out of scope leaks the storage it points to
resource leak from local_namespace_

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>
@@ -163,6 +165,7 @@ rcl_node_init(
ret = rmw_validate_namespace(local_namespace_, &validation_result, NULL);
if (ret != RMW_RET_OK) {
RCL_SET_ERROR_MSG(rmw_get_error_string_safe(), *allocator);
allocator->deallocate((char *)local_namespace_, allocator->state);
Copy link
Member

Choose a reason for hiding this comment

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

This cannot be done if line 147 is executed (if local_namespace_ is a literal string). I think it needs to check should_free_local_namespace_.

Here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly, thanks !

Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

lgtm now, I'll run CI for you:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>
@dhood dhood added the in review Waiting for review (Kanban column) label Nov 2, 2017
@wjwwood wjwwood merged commit f7d7df6 into ros2:master Nov 6, 2017
@wjwwood wjwwood removed the in review Waiting for review (Kanban column) label Nov 6, 2017
@wjwwood
Copy link
Member

wjwwood commented Nov 6, 2017

Thanks @gaoethan!

@dirk-thomas
Copy link
Member

dirk-thomas commented Nov 6, 2017

I don't think the scope of the variable needs to be increased. temp is being used to avoid changing local_namespace_ in case of errors. As long as local_namespace_ is being freed when should_free_local_namespace_ is being set (which is part of this PR) this block should not leak memory anymore.

The scope of temp doesn't affect when it is being cleaned up (since it is a bare pointer) and the variable is not used anywhere below. Therefore I think the scope of temp should be reverted to be local as it was before (keeping the new deallocate calls of course).

@wjwwood
Copy link
Member

wjwwood commented Nov 6, 2017

You’re right, I’ll make a follow up pr ASAP.

wjwwood added a commit that referenced this pull request Nov 7, 2017
wjwwood added a commit that referenced this pull request Nov 8, 2017
@gaoethan gaoethan deleted the fix_node branch November 28, 2017 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants