diff options
author | Antonio Borneo <borneo.antonio@gmail.com> | 2020-08-16 21:35:10 +0200 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2020-09-05 17:11:50 +0100 |
commit | 4e98d44fd1dc67f763f06eeecc0453d65b1290dc (patch) | |
tree | f70d92827b2c6855213a37e9f0b17b5b1fe09109 /src/rtos/chibios.c | |
parent | 62329444abc89ad3b37fbb4ebc2edfd1dee23351 (diff) | |
download | riscv-openocd-4e98d44fd1dc67f763f06eeecc0453d65b1290dc.zip riscv-openocd-4e98d44fd1dc67f763f06eeecc0453d65b1290dc.tar.gz riscv-openocd-4e98d44fd1dc67f763f06eeecc0453d65b1290dc.tar.bz2 |
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).
Replace a pointer assignment to '0' with an assignment to NULL.
In server/*, 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: I10822029fe8390b59edff4070575bf7f754e44ac
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5808
Reviewed-by: Adrian M Negreanu <adrian.negreanu@nxp.com>
Tested-by: jenkins
Diffstat (limited to 'src/rtos/chibios.c')
-rw-r--r-- | src/rtos/chibios.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/rtos/chibios.c b/src/rtos/chibios.c index 4d2b1b2..a56d3ce 100644 --- a/src/rtos/chibios.c +++ b/src/rtos/chibios.c @@ -150,10 +150,8 @@ static int chibios_update_memory_signature(struct rtos *rtos) param = (struct chibios_params *) rtos->rtos_specific_params; /* Free existing memory description.*/ - if (param->signature) { - free(param->signature); - param->signature = 0; - } + free(param->signature); + param->signature = NULL; signature = malloc(sizeof(*signature)); if (!signature) { |