diff options
author | Antonio Borneo <borneo.antonio@gmail.com> | 2020-08-17 09:58:58 +0200 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2020-09-05 20:47:11 +0100 |
commit | 3934483429b77525f25922787933fb7ee3e73a0f (patch) | |
tree | 5cf5d1d4ebe72c1cd437d6b0f6d359465604928d /src/target/nds32.c | |
parent | 0dad8cbfe9e1d43cdcabbc8eb4e2809b7b21381d (diff) | |
download | riscv-openocd-3934483429b77525f25922787933fb7ee3e73a0f.zip riscv-openocd-3934483429b77525f25922787933fb7ee3e73a0f.tar.gz riscv-openocd-3934483429b77525f25922787933fb7ee3e73a0f.tar.bz2 |
target: 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);
In target/openrisc/jsp_server.c, an error is logged if the ptr was
already NULL. This cannot happen since the pointer was already
referenced few lines before and openocd would have been already
SIGSEGV in that case, so remove the log.
Change-Id: I290a32e6d4deab167676af4ddc83523c830ae49e
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5809
Tested-by: jenkins
Diffstat (limited to 'src/target/nds32.c')
-rw-r--r-- | src/target/nds32.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/target/nds32.c b/src/target/nds32.c index 0d1a23a8d..487e19c 100644 --- a/src/target/nds32.c +++ b/src/target/nds32.c @@ -1462,8 +1462,7 @@ int nds32_add_software_breakpoint(struct target *target, break_insn = NDS32_BREAK_32; } - if (breakpoint->orig_instr != NULL) - free(breakpoint->orig_instr); + free(breakpoint->orig_instr); breakpoint->orig_instr = malloc(breakpoint->length); memcpy(breakpoint->orig_instr, &data, breakpoint->length); @@ -2334,10 +2333,8 @@ int nds32_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fil LOG_DEBUG("hit syscall ID: 0x%" PRIx32, syscall_id); /* free previous identifier storage */ - if (NULL != fileio_info->identifier) { - free(fileio_info->identifier); - fileio_info->identifier = NULL; - } + free(fileio_info->identifier); + fileio_info->identifier = NULL; uint32_t reg_r0, reg_r1, reg_r2; nds32_get_mapped_reg(nds32, R0, ®_r0); |