From de026b96f733eaf290cf750ef51a856360cab6be Mon Sep 17 00:00:00 2001 From: Chris Ye Date: Thu, 16 Aug 2018 15:14:32 +0800 Subject: [PATCH] Fix deallocate issue of parameter_files Correct pointer arithmetic on parameter_files to avoid deallocate memory out-of-bounds Signed-off-by: Chris Ye --- rcl/src/rcl/arguments.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rcl/src/rcl/arguments.c b/rcl/src/rcl/arguments.c index 6b05dec0a..8a58cb550 100644 --- a/rcl/src/rcl/arguments.c +++ b/rcl/src/rcl/arguments.c @@ -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;