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

Make sure to always check return values. #840

Merged
merged 3 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion rcl_action/src/rcl_action/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ _filter_action_names(
// Cleanup if there is an error
if (RCL_RET_OK != ret) {
rcl_ret_t fini_ret = rcl_names_and_types_fini(action_names_and_types);
(void)fini_ret; // Error already set
if (RCL_RET_OK != fini_ret) {
RCUTILS_SAFE_FWRITE_TO_STDERR(
"Freeing names and types failed while handling a previous error. Leaking memory!\n");
}
}

return ret;
Expand Down Expand Up @@ -154,6 +157,10 @@ rcl_action_get_client_names_and_types_by_node(
rcl_ret_t nat_fini_ret = rcl_names_and_types_fini(&topic_names_and_types);
if (RCL_RET_OK != nat_fini_ret) {
ret = rcl_names_and_types_fini(action_names_and_types);
if (RCL_RET_OK != ret) {
RCUTILS_SAFE_FWRITE_TO_STDERR(
"Freeing names and types failed while handling a previous error. Leaking memory!\n");
}
return nat_fini_ret;
}
return ret;
Expand Down Expand Up @@ -185,6 +192,11 @@ rcl_action_get_server_names_and_types_by_node(
rcl_ret_t nat_fini_ret = rcl_names_and_types_fini(&topic_names_and_types);
if (RCL_RET_OK != nat_fini_ret) {
ret = rcl_names_and_types_fini(action_names_and_types);
if (RCL_RET_OK != ret) {
RCUTILS_SAFE_FWRITE_TO_STDERR(
"Freeing names and types failed while handling a previous error. Leaking memory!\n");
}

return nat_fini_ret;
}
return ret;
Expand All @@ -211,6 +223,10 @@ rcl_action_get_names_and_types(
rcl_ret_t nat_fini_ret = rcl_names_and_types_fini(&topic_names_and_types);
if (RCL_RET_OK != nat_fini_ret) {
ret = rcl_names_and_types_fini(action_names_and_types);
if (RCL_RET_OK != ret) {
RCUTILS_SET_ERROR_MSG(
"Freeing names and types failed while handling a previous error. Leaking memory!\n");
}
return nat_fini_ret;
}
return ret;
Expand Down
4 changes: 4 additions & 0 deletions rcl_lifecycle/src/rcl_lifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ rcl_lifecycle_state_machine_init(
// init default state machine might have allocated memory,
// so we have to call fini
ret = rcl_lifecycle_state_machine_fini(state_machine, node_handle, allocator);
if (ret != RCL_RET_OK) {
RCUTILS_SAFE_FWRITE_TO_STDERR(
"Freeing state machine failed while handling a previous error. Leaking memory!\n");
}
return RCL_RET_ERROR;
}
}
Expand Down