This is an automated email from Gerrit. Antonio Borneo ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/5808
-- gerrit commit f84129bb8e84470e6aa0555058e23cfa8bc96f7d Author: Antonio Borneo <[email protected]> Date: Sun Aug 16 21:35:10 2020 +0200 openocd: avoid checking for non NULL pointer to free it The function free() can be called with a NULL pointer as argument, no need to check the argument before. If the pointer is NULL, no operation is performed by free(). Remove the occurrences of pattern: if (ptr) free(ptr); While there replace a sequence malloc(size)+memset(,0,size) with a calloc(1,size). Change-Id: I10822029fe8390b59edff4070575bf7f754e44ac Signed-off-by: Antonio Borneo <[email protected]> diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 8b76bff..3f14f9b 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -1155,10 +1155,8 @@ COMMAND_HANDLER(handle_irscan_command) retval = jtag_execute_queue(); error_return: - for (i = 0; i < num_fields; i++) { - if (NULL != fields[i].out_value) - free((void *)fields[i].out_value); - } + for (i = 0; i < num_fields; i++) + free((void *)fields[i].out_value); free(fields); diff --git a/src/rtos/linux.c b/src/rtos/linux.c index cd1ed21..31ebba7 100644 --- a/src/rtos/linux.c +++ b/src/rtos/linux.c @@ -627,8 +627,7 @@ struct threads *liste_del_task(struct threads *task_list, struct threads **t, task_list = (*t)->next; /* free content of threads */ - if ((*t)->context) - free((*t)->context); + free((*t)->context); free(*t); *t = prev ? prev : task_list; diff --git a/src/svf/svf.c b/src/svf/svf.c index 0105920..69454a9 100644 --- a/src/svf/svf.c +++ b/src/svf/svf.c @@ -771,16 +771,12 @@ static int svf_adjust_array_length(uint8_t **arr, int orig_bit_len, int new_bit_ int new_byte_len = (new_bit_len + 7) >> 3; if ((NULL == *arr) || (((orig_bit_len + 7) >> 3) < ((new_bit_len + 7) >> 3))) { - if (*arr != NULL) { - free(*arr); - *arr = NULL; - } - *arr = malloc(new_byte_len); + free(*arr); + *arr = calloc(1, new_byte_len); if (NULL == *arr) { LOG_ERROR("not enough memory"); return ERROR_FAIL; } - memset(*arr, 0, new_byte_len); } return ERROR_OK; } diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index afd0cc8..e84efc0 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -1558,8 +1558,7 @@ int parse_ranges(range_t **ranges, const char **argv) } if (pass == 0) { - if (*ranges) - free(*ranges); + free(*ranges); *ranges = calloc(range + 2, sizeof(range_t)); } else { (*ranges)[range].low = 1; -- _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
