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/openrisc | |
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/openrisc')
-rw-r--r-- | src/target/openrisc/jsp_server.c | 8 | ||||
-rw-r--r-- | src/target/openrisc/or1k.c | 3 | ||||
-rw-r--r-- | src/target/openrisc/or1k_du_adv.c | 7 |
3 files changed, 5 insertions, 13 deletions
diff --git a/src/target/openrisc/jsp_server.c b/src/target/openrisc/jsp_server.c index f28815d..1d05944 100644 --- a/src/target/openrisc/jsp_server.c +++ b/src/target/openrisc/jsp_server.c @@ -190,12 +190,8 @@ static int jsp_connection_closed(struct connection *connection) if (ERROR_OK != retval) return retval; - if (connection->priv) { - free(connection->priv); - connection->priv = NULL; - } else - LOG_ERROR("BUG: connection->priv == NULL"); - + free(connection->priv); + connection->priv = NULL; return ERROR_OK; } diff --git a/src/target/openrisc/or1k.c b/src/target/openrisc/or1k.c index 93fb9c6..d685359 100644 --- a/src/target/openrisc/or1k.c +++ b/src/target/openrisc/or1k.c @@ -943,8 +943,7 @@ static int or1k_add_breakpoint(struct target *target, return retval; } - 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); diff --git a/src/target/openrisc/or1k_du_adv.c b/src/target/openrisc/or1k_du_adv.c index afc773f..31b2487 100644 --- a/src/target/openrisc/or1k_du_adv.c +++ b/src/target/openrisc/or1k_du_adv.c @@ -975,8 +975,7 @@ static int or1k_adv_jtag_write_memory(struct or1k_jtag *jtag_info, size, blocks_this_round, block_count_address); if (retval != ERROR_OK) { - if (t != NULL) - free(t); + free(t); return retval; } @@ -985,9 +984,7 @@ static int or1k_adv_jtag_write_memory(struct or1k_jtag *jtag_info, block_count_buffer += size * MAX_BURST_SIZE; } - if (t != NULL) - free(t); - + free(t); return ERROR_OK; } |