aboutsummaryrefslogtreecommitdiff
path: root/src/rtos
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
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')
-rw-r--r--src/rtos/chibios.c6
-rw-r--r--src/rtos/linux.c12
-rw-r--r--src/rtos/rtos.c11
3 files changed, 10 insertions, 19 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) {
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;
}
diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c
index 97ce255..62b65aa 100644
--- a/src/rtos/rtos.c
+++ b/src/rtos/rtos.c
@@ -100,9 +100,7 @@ static void os_free(struct target *target)
if (!target->rtos)
return;
- if (target->rtos->symbols)
- free(target->rtos->symbols);
-
+ free(target->rtos->symbols);
free(target->rtos);
target->rtos = NULL;
}
@@ -646,10 +644,9 @@ int rtos_try_next(struct target *target)
return 0;
os->type = *type;
- if (os->symbols) {
- free(os->symbols);
- os->symbols = NULL;
- }
+
+ free(os->symbols);
+ os->symbols = NULL;
return 1;
}