Fix deallocate issue of parameter_files (#279)
Correct pointer arithmetic on parameter_files to avoid deallocate memory out-of-bounds Signed-off-by: Chris Ye <chris.ye@intel.com>
This commit is contained in:
parent
696f62c80b
commit
adc0190259
1 changed files with 5 additions and 2 deletions
|
@ -91,10 +91,13 @@ rcl_arguments_get_param_files(
|
||||||
}
|
}
|
||||||
for (int i = 0; i < arguments->impl->num_param_files_args; ++i) {
|
for (int i = 0; i < arguments->impl->num_param_files_args; ++i) {
|
||||||
(*parameter_files)[i] = rcutils_strdup(arguments->impl->parameter_files[i], allocator);
|
(*parameter_files)[i] = rcutils_strdup(arguments->impl->parameter_files[i], allocator);
|
||||||
if (NULL == *parameter_files) {
|
if (NULL == (*parameter_files)[i]) {
|
||||||
// deallocate allocated memory
|
// deallocate allocated memory
|
||||||
for (int r = i; r >= 0; --r) {
|
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);
|
allocator.deallocate((*parameter_files), allocator.state);
|
||||||
(*parameter_files) = NULL;
|
(*parameter_files) = NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue