native_posix: Fix realloc potential leak
Fix a possible leak if `realloc` fails here; check the result of the `realloc` call before updating the pointer, so it can be freed in the failure case. Signed-off-by: Noah Pendleton <noah.pendleton@gmail.com>
This commit is contained in:
parent
9bb7da060b
commit
d0abd9a104
1 changed files with 4 additions and 2 deletions
|
@ -54,13 +54,15 @@ void native_add_command_line_opts(struct args_struct_t *args)
|
||||||
growby = ARGS_ALLOC_CHUNK_SIZE;
|
growby = ARGS_ALLOC_CHUNK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
args_struct = realloc(args_struct,
|
struct args_struct_t *new_args_struct = realloc(args_struct,
|
||||||
(args_aval + growby)*
|
(args_aval + growby)*
|
||||||
sizeof(struct args_struct_t));
|
sizeof(struct args_struct_t));
|
||||||
args_aval += growby;
|
args_aval += growby;
|
||||||
/* LCOV_EXCL_START */
|
/* LCOV_EXCL_START */
|
||||||
if (args_struct == NULL) {
|
if (new_args_struct == NULL) {
|
||||||
posix_print_error_and_exit("Could not allocate memory");
|
posix_print_error_and_exit("Could not allocate memory");
|
||||||
|
} else {
|
||||||
|
args_struct = new_args_struct;
|
||||||
}
|
}
|
||||||
/* LCOV_EXCL_STOP */
|
/* LCOV_EXCL_STOP */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue