aboutsummaryrefslogtreecommitdiff
path: root/src/rtos/linux.c
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2020-08-16 21:35:10 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2020-09-05 17:11:50 +0100
commit4e98d44fd1dc67f763f06eeecc0453d65b1290dc (patch)
treef70d92827b2c6855213a37e9f0b17b5b1fe09109 /src/rtos/linux.c
parent62329444abc89ad3b37fbb4ebc2edfd1dee23351 (diff)
downloadriscv-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/linux.c')
-rw-r--r--src/rtos/linux.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/rtos/linux.c b/src/rtos/linux.c
index cd1ed21..dbbf97b 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;
@@ -781,8 +780,7 @@ static int clean_threadlist(struct target *target)
while (temp != NULL) {
old = temp;
- if (temp->context)
- free(temp->context);
+ free(temp->context);
temp = temp->next;
free(old);
@@ -931,10 +929,8 @@ static int linux_task_update(struct target *target, int context)
while (thread_list != NULL) {
thread_list->status = 0; /*setting all tasks to dead state*/
- if (thread_list->context) {
- free(thread_list->context);
- thread_list->context = NULL;
- }
+ free(thread_list->context);
+ thread_list->context = NULL;
thread_list = thread_list->next;
}