Skip to content

Commit

Permalink
Fix potential leak and improve readability
Browse files Browse the repository at this point in the history
Signed-off-by: y-okumura-isp <[email protected]>
  • Loading branch information
y-okumura-isp committed Mar 6, 2020
1 parent 42239d6 commit 09a692c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
16 changes: 7 additions & 9 deletions rcl/src/rcl/arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,12 +962,10 @@ rcl_arguments_copy(

rcl_allocator_t allocator = args->impl->allocator;

do {
rcl_ret_t ret = _rcl_allocate_initialized_arguments_impl(args_out, &allocator);
if (RCL_RET_OK != ret) {
return ret;
}
} while(false);
rcl_ret_t ret = _rcl_allocate_initialized_arguments_impl(args_out, &allocator);
if (RCL_RET_OK != ret) {
return ret;
}

if (args->impl->num_unparsed_args) {
// Copy unparsed args
Expand Down Expand Up @@ -1014,7 +1012,7 @@ rcl_arguments_copy(
args_out->impl->num_remap_rules = args->impl->num_remap_rules;
for (int i = 0; i < args->impl->num_remap_rules; ++i) {
args_out->impl->remap_rules[i] = rcl_get_zero_initialized_remap();
rcl_ret_t ret = rcl_remap_copy(
ret = rcl_remap_copy(
&(args->impl->remap_rules[i]), &(args_out->impl->remap_rules[i]));
if (RCL_RET_OK != ret) {
if (RCL_RET_OK != rcl_arguments_fini(args_out)) {
Expand Down Expand Up @@ -1102,8 +1100,8 @@ rcl_arguments_fini(
}

if (NULL != args->impl->external_log_config_file) {
args->impl->allocator.deallocate(args->impl->external_log_config_file,
args->impl->allocator.state);
args->impl->allocator.deallocate(
args->impl->external_log_config_file, args->impl->allocator.state);
args->impl->external_log_config_file = NULL;
}

Expand Down
5 changes: 2 additions & 3 deletions rcl_yaml_param_parser/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1343,13 +1343,12 @@ static rcutils_ret_t parse_key(
}

ret = find_node(node_name_ns, params_st, node_idx);
allocator.deallocate(node_name_ns, allocator.state);
if (RCUTILS_RET_OK != ret) {
break;
}

allocator.deallocate(node_name_ns, allocator.state);

ret = rem_name_from_ns(ns_tracker, NS_TYPE_NODE, allocator);
ret = rem_name_from_ns(ns_tracker, NS_TYPE_NODE, allocator);
if (RCUTILS_RET_OK != ret) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Internal error adding node namespace at line %d", line_num);
Expand Down

0 comments on commit 09a692c

Please sign in to comment.