Skip to content

Commit

Permalink
Fix deallocate issue of parameter_files (#279)
Browse files Browse the repository at this point in the history
Correct pointer arithmetic on parameter_files to avoid deallocate memory out-of-bounds

Signed-off-by: Chris Ye <chris.ye@intel.com>
  • Loading branch information
yechun1 authored and mjcarroll committed Aug 16, 2018
1 parent 696f62c commit adc0190
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions rcl/src/rcl/arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ rcl_arguments_get_param_files(
}
for (int i = 0; i < arguments->impl->num_param_files_args; ++i) {
(*parameter_files)[i] = rcutils_strdup(arguments->impl->parameter_files[i], allocator);
if (NULL == *parameter_files) {
if (NULL == (*parameter_files)[i]) {
// deallocate allocated memory
for (int r = i; r >= 0; --r) {
allocator.deallocate((*parameter_files[i]), allocator.state);
if (NULL == (*parameter_files[r])) {
break;
}
allocator.deallocate((*parameter_files[r]), allocator.state);
}
allocator.deallocate((*parameter_files), allocator.state);
(*parameter_files) = NULL;
Expand Down

0 comments on commit adc0190

Please sign in to comment.