Skip to content

Commit f8a75fa

Browse files
committed
Make sure to always check return values.
Pointed out by clang static analysis, we should always check these return values. Signed-off-by: Chris Lalancette <[email protected]>
1 parent 5ef4b2d commit f8a75fa

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

rcl_action/src/rcl_action/graph.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ _filter_action_names(
122122
// Cleanup if there is an error
123123
if (RCL_RET_OK != ret) {
124124
rcl_ret_t fini_ret = rcl_names_and_types_fini(action_names_and_types);
125-
(void)fini_ret; // Error already set
125+
if (RCL_RET_OK != fini_ret) {
126+
RCUTILS_SAFE_FWRITE_TO_STDERR(
127+
"Freeing names and types failed while handling a previous error. Leaking memory!");
128+
}
126129
}
127130

128131
return ret;
@@ -154,6 +157,10 @@ rcl_action_get_client_names_and_types_by_node(
154157
rcl_ret_t nat_fini_ret = rcl_names_and_types_fini(&topic_names_and_types);
155158
if (RCL_RET_OK != nat_fini_ret) {
156159
ret = rcl_names_and_types_fini(action_names_and_types);
160+
if (RCL_RET_OK != ret) {
161+
RCUTILS_SAFE_FWRITE_TO_STDERR(
162+
"Freeing names and types failed while handling a previous error. Leaking memory!");
163+
}
157164
return nat_fini_ret;
158165
}
159166
return ret;
@@ -185,6 +192,11 @@ rcl_action_get_server_names_and_types_by_node(
185192
rcl_ret_t nat_fini_ret = rcl_names_and_types_fini(&topic_names_and_types);
186193
if (RCL_RET_OK != nat_fini_ret) {
187194
ret = rcl_names_and_types_fini(action_names_and_types);
195+
if (RCL_RET_OK != ret) {
196+
RCUTILS_SAFE_FWRITE_TO_STDERR(
197+
"Freeing names and types failed while handling a previous error. Leaking memory!");
198+
}
199+
188200
return nat_fini_ret;
189201
}
190202
return ret;
@@ -211,6 +223,10 @@ rcl_action_get_names_and_types(
211223
rcl_ret_t nat_fini_ret = rcl_names_and_types_fini(&topic_names_and_types);
212224
if (RCL_RET_OK != nat_fini_ret) {
213225
ret = rcl_names_and_types_fini(action_names_and_types);
226+
if (RCL_RET_OK != ret) {
227+
RCUTILS_SET_ERROR_MSG(
228+
"Freeing names and types failed while handling a previous error. Leaking memory!");
229+
}
214230
return nat_fini_ret;
215231
}
216232
return ret;

rcl_lifecycle/src/rcl_lifecycle.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ rcl_lifecycle_state_machine_init(
216216
// init default state machine might have allocated memory,
217217
// so we have to call fini
218218
ret = rcl_lifecycle_state_machine_fini(state_machine, node_handle, allocator);
219+
if (ret != RCL_RET_OK) {
220+
RCUTILS_SAFE_FWRITE_TO_STDERR(
221+
"Freeing state machine failed while handling a previous error. Leaking memory!");
222+
}
219223
return RCL_RET_ERROR;
220224
}
221225
}

0 commit comments

Comments
 (0)