Skip to content

Commit

Permalink
Make finishing zero initialized log levels structure safe
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno committed Jul 8, 2020
1 parent c8dab5f commit d795983
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
17 changes: 7 additions & 10 deletions rcl/src/rcl/arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ rcl_arguments_get_log_levels(
const rcl_allocator_t * allocator = &arguments->impl->allocator;
RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT);

rcl_ret_t ret = rcl_log_levels_copy(&arguments->impl->log_levels, log_levels);
return RCL_RET_OK;
return rcl_log_levels_copy(&arguments->impl->log_levels, log_levels);
}

/// Parse an argument that may or may not be a log level rule.
Expand Down Expand Up @@ -945,14 +944,12 @@ rcl_arguments_fini(
args->impl->num_remap_rules = 0;
}

if (args->impl->log_levels.logger_settings) {
rcl_ret_t log_levels_ret = rcl_log_levels_fini(&args->impl->log_levels);
if (log_levels_ret != RCL_RET_OK) {
ret = log_levels_ret;
RCUTILS_LOG_ERROR_NAMED(
ROS_PACKAGE_NAME,
"Failed to finalize log levels while finalizing arguments. Continuing...");
}
rcl_ret_t log_levels_ret = rcl_log_levels_fini(&args->impl->log_levels);
if (log_levels_ret != RCL_RET_OK) {
ret = log_levels_ret;
RCUTILS_LOG_ERROR_NAMED(
ROS_PACKAGE_NAME,
"Failed to finalize log levels while finalizing arguments. Continuing...");
}

args->impl->allocator.deallocate(args->impl->unparsed_args, args->impl->allocator.state);
Expand Down
3 changes: 2 additions & 1 deletion rcl/src/rcl/log_level.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ rcl_log_levels_fini(rcl_log_levels_t * log_levels)
{
RCL_CHECK_ARGUMENT_FOR_NULL(log_levels, RCL_RET_INVALID_ARGUMENT);
const rcl_allocator_t * allocator = &log_levels->allocator;
RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT);
if (log_levels->logger_settings) {
// check allocator here, so it's safe to finish a zero initialized rcl_log_levels_t
RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT);
for (size_t i = 0; i < log_levels->num_logger_settings; ++i) {
allocator->deallocate((void *)log_levels->logger_settings[i].name, allocator->state);
}
Expand Down

0 comments on commit d795983

Please sign in to comment.