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

Improve error handling to avoid memory leaks in C extension #278

Merged
merged 4 commits into from
Mar 25, 2019

Conversation

jacobperron
Copy link
Member

@jacobperron jacobperron commented Mar 2, 2019

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

Edit: test failures are unrelated.

@jacobperron jacobperron added the in progress Actively being worked on (Kanban column) label Mar 2, 2019
@jacobperron jacobperron self-assigned this Mar 14, 2019
@jacobperron jacobperron added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Mar 14, 2019
Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

LGTM but for a few comments and pending greener CI.

rcutils_ret_t fini_namespaces_ret;
cleanup:
fini_names_ret = rcutils_string_array_fini(&node_names);
fini_namespaces_ret = rcutils_string_array_fini(&node_namespaces);
Copy link
Contributor

Choose a reason for hiding this comment

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

@jacobperron nit: can't we declare and initialize on the same statement?

Copy link
Member Author

@jacobperron jacobperron Mar 22, 2019

Choose a reason for hiding this comment

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

Apparently, declarations directly after a label are not supported and results in compiler errors. This SO post suggest we could add an empty statement as a workaround. I don't feel strongly either way, but I'm leaning towards leaving it as-is because cleanup:; looks odd to me.

Copy link
Member

Choose a reason for hiding this comment

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

I'm actually surprised you don't have warnings above where you declare local variables after the use of a goto. In the rmw implementations we declare all local variables just before the first use of goto, which is essentially what the compiler does even when you declare them throughout and I gather the use of goto might cause strange order of side-effects if you don't declare everything ahead of their use.

For example:

https://github.com/ros2/rmw_connext/blob/43d6833977ddfc3d8fa599a51c7b01bcb3008fa3/rmw_connext_shared_cpp/src/node.cpp#L119-L140

Copy link
Member Author

@jacobperron jacobperron Mar 22, 2019

Choose a reason for hiding this comment

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

Yeah, in retrospect this is odd.
I am able to produce an error if I try to both declare and initialize after a goto statement. But the compiler is fine if it's only a declaration. I've moved the declarations before the first goto statement so code reads better 67d3660

rclpy/src/rclpy/_rclpy.c Outdated Show resolved Hide resolved
rclpy/src/rclpy/_rclpy.c Outdated Show resolved Hide resolved
Copy link
Contributor

@sloretz sloretz left a comment

Choose a reason for hiding this comment

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

lots of good fixes on the error handling. Just the same minor comment in a few places

rclpy/src/rclpy/_rclpy.c Show resolved Hide resolved
rclpy/src/rclpy/_rclpy.c Show resolved Hide resolved
rclpy/src/rclpy/_rclpy.c Show resolved Hide resolved
rclpy/src/rclpy/_rclpy.c Show resolved Hide resolved
Signed-off-by: Jacob Perron <[email protected]>
@jacobperron
Copy link
Member Author

jacobperron commented Mar 22, 2019

Thanks for the reviews!

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

(I expect test_params_yaml to fail ros2/build_farmer#166)

@jacobperron jacobperron merged commit 5b5b815 into master Mar 25, 2019
@jacobperron jacobperron deleted the jacob/c_ext_err_handling branch March 25, 2019 16:06
@jacobperron jacobperron removed the in review Waiting for review (Kanban column) label Mar 25, 2019
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