RTOS: Unify wipe-out of thread list

Each RTOS implementation uses it's own (similar) code to free
the thread list. There are some additional issues:

<--->
if (pointer != NULL)
	free(pointer);
<--->
This is not necessary, free(NULL) is perfectly ok.

<--->
free(rtos->thread_details);
rtos->thread_details = NULL;
rtos->thread_count = 0;
<--->
The 3rd line has been missing for all RTOS but ChibiOs. There are paths
in the code where rtos->thread_count is never set to NULL, which can
lead to null pointer dereference of rtos->thread_details.

Change-Id: I6f7045c3d4518b925cb80dd5c907a566536b34ad
Signed-off-by: Christian Eggers <ceggers@gmx.de>
---
Changelog:
v7:
- rtos_wipe_threadlist() --> rtos_free_threadlist()
- removed non related changes in gdb_server.c from this patch
v3:
- Removed world "topic" from first line of commit message
v2:
- typo: "whipe" --> "wipe"
Reviewed-on: http://openocd.zylin.com/1916
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
This commit is contained in:
Christian Eggers
2014-02-01 10:17:17 +01:00
committed by Spencer Oliver
parent bc1340cf0b
commit d36889e692
7 changed files with 24 additions and 91 deletions

View File

@@ -296,21 +296,8 @@ static int ChibiOS_update_threads(struct rtos *rtos)
}
/* wipe out previous thread details if any */
int j;
if (rtos->thread_details) {
for (j = 0; j < rtos->thread_count; j++) {
struct thread_detail *current_thread = &rtos->thread_details[j];
if (current_thread->display_str != NULL)
free(current_thread->display_str);
if (current_thread->thread_name_str != NULL)
free(current_thread->thread_name_str);
if (current_thread->extra_info_str != NULL)
free(current_thread->extra_info_str);
}
free(rtos->thread_details);
rtos->thread_details = NULL;
rtos->thread_count = 0;
}
rtos_free_threadlist(rtos);
/* ChibiOS does not save the current thread count. We have to first
* parse the double linked thread list to check for errors and the number of
* threads. */