-
Notifications
You must be signed in to change notification settings - Fork 422
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
Correctly clean up arguments structure. #459
Changes from 1 commit
b0ee260
f6f5794
f284100
c960ce2
d714b38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -210,7 +210,16 @@ rclcpp::remove_ros_arguments(int argc, char const * const argv[]) | |||
|
||||
ret = rcl_parse_arguments(argc, argv, alloc, &parsed_args); | ||||
if (RCL_RET_OK != ret) { | ||||
exceptions::throw_from_rcl_error(ret, "Failed to parse arguments"); | ||||
// Not using throw_from_rcl_error, because we may need to append deallocation failures. | ||||
exceptions::RCLErrorBase base_exec(ret, rcl_get_error_state()); | ||||
rcl_reset_error(); | ||||
if (RCL_RET_OK != rcl_arguments_fini(&parsed_args)) { | ||||
base_exec.formatted_message += std::string( | ||||
", failed also to cleanup parsed arguments, leaking memory: ") + | ||||
rcl_get_error_string_safe(); | ||||
rcl_reset_error(); | ||||
} | ||||
throw base_exec; | ||||
} | ||||
|
||||
int nonros_argc = 0; | ||||
|
@@ -224,10 +233,19 @@ rclcpp::remove_ros_arguments(int argc, char const * const argv[]) | |||
&nonros_argv); | ||||
|
||||
if (RCL_RET_OK != ret) { | ||||
// Not using throw_from_rcl_error, because we may need to append deallocation failures. | ||||
exceptions::RCLErrorBase base_exec(ret, rcl_get_error_state()); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unless it's a convention that I haven't seen before, |
||||
rcl_reset_error(); | ||||
if (NULL != nonros_argv) { | ||||
alloc.deallocate(nonros_argv, alloc.state); | ||||
} | ||||
exceptions::throw_from_rcl_error(ret, "Failed to remove ROS arguments: "); | ||||
if (RCL_RET_OK != rcl_arguments_fini(&parsed_args)) { | ||||
base_exec.formatted_message += std::string( | ||||
", failed also to cleanup parsed arguments, leaking memory: ") + | ||||
rcl_get_error_string_safe(); | ||||
rcl_reset_error(); | ||||
} | ||||
throw base_exec; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think our default behaviour is to throw an
|
||||
} | ||||
|
||||
std::vector<std::string> return_arguments; | ||||
|
@@ -241,6 +259,11 @@ rclcpp::remove_ros_arguments(int argc, char const * const argv[]) | |||
alloc.deallocate(nonros_argv, alloc.state); | ||||
} | ||||
|
||||
ret = rcl_arguments_fini(&parsed_args); | ||||
if (RCL_RET_OK != ret) { | ||||
exceptions::throw_from_rcl_error(ret, "failed to cleanup parsed arguments, leaking memory: "); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the rclcpp/rclcpp/src/rclcpp/exceptions.cpp Line 60 in 45dcd0c
|
||||
} | ||||
|
||||
return return_arguments; | ||||
} | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like
rcl_parse_arguments
cleans up after itself when something goes wrong. I would expect this call torcl_arguments_fini
to always fail here.