This is an automated email from Gerrit.

Christian Eggers (cegg...@gmx.de) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/1916

-- gerrit

commit 9906bde0751653f1aa0eb35aacdf6fd37dedeb55
Author: Christian Eggers <cegg...@gmx.de>
Date:   Sat Feb 1 10:17:17 2014 +0100

    topic: RTOS: Unify whipe-out of thread list
    
    Each RTOS implementation uses it's own (similar) code to whipe out
    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 <cegg...@gmx.de>

diff --git a/src/rtos/ChibiOS.c b/src/rtos/ChibiOS.c
index 2148e91..c81255d 100644
--- a/src/rtos/ChibiOS.c
+++ b/src/rtos/ChibiOS.c
@@ -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_whipe_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. */
diff --git a/src/rtos/FreeRTOS.c b/src/rtos/FreeRTOS.c
index 321b1e1..4047a65 100644
--- a/src/rtos/FreeRTOS.c
+++ b/src/rtos/FreeRTOS.c
@@ -173,25 +173,7 @@ static int FreeRTOS_update_threads(struct rtos *rtos)
        }
 
        /* wipe out previous thread details if any */
-       if (rtos->thread_details != NULL) {
-               int j;
-               for (j = 0; j < rtos->thread_count; j++) {
-                       if (rtos->thread_details[j].display_str != NULL) {
-                               free(rtos->thread_details[j].display_str);
-                               rtos->thread_details[j].display_str = NULL;
-                       }
-                       if (rtos->thread_details[j].thread_name_str != NULL) {
-                               free(rtos->thread_details[j].thread_name_str);
-                               rtos->thread_details[j].thread_name_str = NULL;
-                       }
-                       if (rtos->thread_details[j].extra_info_str != NULL) {
-                               free(rtos->thread_details[j].extra_info_str);
-                               rtos->thread_details[j].extra_info_str = NULL;
-                       }
-               }
-               free(rtos->thread_details);
-               rtos->thread_details = NULL;
-       }
+       rtos_whipe_threadlist(rtos);
 
        /* read the current thread */
        retval = target_read_buffer(rtos->target,
diff --git a/src/rtos/ThreadX.c b/src/rtos/ThreadX.c
index 19dc463..d05e29f 100644
--- a/src/rtos/ThreadX.c
+++ b/src/rtos/ThreadX.c
@@ -155,25 +155,7 @@ static int ThreadX_update_threads(struct rtos *rtos)
        }
 
        /* wipe out previous thread details if any */
-       if (rtos->thread_details != NULL) {
-               int j;
-               for (j = 0; j < rtos->thread_count; j++) {
-                       if (rtos->thread_details[j].display_str != NULL) {
-                               free(rtos->thread_details[j].display_str);
-                               rtos->thread_details[j].display_str = NULL;
-                       }
-                       if (rtos->thread_details[j].thread_name_str != NULL) {
-                               free(rtos->thread_details[j].thread_name_str);
-                               rtos->thread_details[j].thread_name_str = NULL;
-                       }
-                       if (rtos->thread_details[j].extra_info_str != NULL) {
-                               free(rtos->thread_details[j].extra_info_str);
-                               rtos->thread_details[j].extra_info_str = NULL;
-                       }
-               }
-               free(rtos->thread_details);
-               rtos->thread_details = NULL;
-       }
+       rtos_whipe_threadlist(rtos);
 
        /* read the current thread id */
        retval = target_read_buffer(rtos->target,
diff --git a/src/rtos/eCos.c b/src/rtos/eCos.c
index 9ab88de..ddf49ef 100644
--- a/src/rtos/eCos.c
+++ b/src/rtos/eCos.c
@@ -125,25 +125,7 @@ static int eCos_update_threads(struct rtos *rtos)
        }
 
        /* wipe out previous thread details if any */
-       if (rtos->thread_details != NULL) {
-               int j;
-               for (j = 0; j < rtos->thread_count; j++) {
-                       if (rtos->thread_details[j].display_str != NULL) {
-                               free(rtos->thread_details[j].display_str);
-                               rtos->thread_details[j].display_str = NULL;
-                       }
-                       if (rtos->thread_details[j].thread_name_str != NULL) {
-                               free(rtos->thread_details[j].thread_name_str);
-                               rtos->thread_details[j].thread_name_str = NULL;
-                       }
-                       if (rtos->thread_details[j].extra_info_str != NULL) {
-                               free(rtos->thread_details[j].extra_info_str);
-                               rtos->thread_details[j].extra_info_str = NULL;
-                       }
-               }
-               free(rtos->thread_details);
-               rtos->thread_details = NULL;
-       }
+       rtos_whipe_threadlist(rtos);
 
        /* determine the number of current threads */
        uint32_t thread_list_head = rtos->symbols[eCos_VAL_thread_list].address;
diff --git a/src/rtos/embKernel.c b/src/rtos/embKernel.c
index f605deb..15e48f0 100644
--- a/src/rtos/embKernel.c
+++ b/src/rtos/embKernel.c
@@ -206,25 +206,7 @@ static int embKernel_update_threads(struct rtos *rtos)
        }
 
        /* wipe out previous thread details if any */
-       if (rtos->thread_details != NULL) {
-               int j;
-               for (j = 0; j < rtos->thread_count; j++) {
-                       if (rtos->thread_details[j].display_str != NULL) {
-                               free(rtos->thread_details[j].display_str);
-                               rtos->thread_details[j].display_str = NULL;
-                       }
-                       if (rtos->thread_details[j].thread_name_str != NULL) {
-                               free(rtos->thread_details[j].thread_name_str);
-                               rtos->thread_details[j].thread_name_str = NULL;
-                       }
-                       if (rtos->thread_details[j].extra_info_str != NULL) {
-                               free(rtos->thread_details[j].extra_info_str);
-                               rtos->thread_details[j].extra_info_str = NULL;
-                       }
-               }
-               free(rtos->thread_details);
-               rtos->thread_details = NULL;
-       }
+       rtos_whipe_threadlist(rtos);
 
        param = (const struct embKernel_params *) rtos->rtos_specific_params;
 
diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c
index 11cb792..aadc467 100644
--- a/src/rtos/rtos.c
+++ b/src/rtos/rtos.c
@@ -513,3 +513,20 @@ int rtos_update_threads(struct target *target)
                target->rtos->type->update_threads(target->rtos);
        return ERROR_OK;
 }
+
+void rtos_whipe_threadlist(struct rtos *rtos)
+{
+       if (rtos->thread_details) {
+               int j;
+
+               for (j = 0; j < rtos->thread_count; j++) {
+                       struct thread_detail *current_thread = 
&rtos->thread_details[j];
+                       free(current_thread->display_str);
+                       free(current_thread->thread_name_str);
+                       free(current_thread->extra_info_str);
+               }
+               free(rtos->thread_details);
+               rtos->thread_details = NULL;
+               rtos->thread_count = 0;
+       }
+}
diff --git a/src/rtos/rtos.h b/src/rtos/rtos.h
index 12a96d2..1ff4f11 100644
--- a/src/rtos/rtos.h
+++ b/src/rtos/rtos.h
@@ -98,6 +98,7 @@ int rtos_try_next(struct target *target);
 int gdb_thread_packet(struct connection *connection, char *packet, int 
packet_size);
 int rtos_get_gdb_reg_list(struct connection *connection);
 int rtos_update_threads(struct target *target);
+void rtos_whipe_threadlist(struct rtos *rtos);
 int rtos_smp_init(struct target *target);
 /*  function for handling symbol access */
 int rtos_qsymbol(struct connection *connection, char *packet, int packet_size);

-- 

------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to