diff --git a/src/rtos/hwthread.c b/src/rtos/hwthread.c index bdd5835c2..e5eaf425f 100644 --- a/src/rtos/hwthread.c +++ b/src/rtos/hwthread.c @@ -78,6 +78,7 @@ static int hwthread_fill_thread(struct rtos *rtos, struct target *curr, int thre static int hwthread_update_threads(struct rtos *rtos) { int threads_found = 0; + int thread_list_size = 0; struct target_list *head; struct target *target; int64_t current_thread = 0; @@ -99,13 +100,13 @@ static int hwthread_update_threads(struct rtos *rtos) if (!target_was_examined(curr)) continue; - ++threads_found; + ++thread_list_size; } } else - threads_found = 1; + thread_list_size = 1; /* create space for new thread details */ - rtos->thread_details = malloc(sizeof(struct thread_detail) * threads_found); + rtos->thread_details = malloc(sizeof(struct thread_detail) * thread_list_size); if (target->smp) { /* loop over all threads */ @@ -170,10 +171,13 @@ static int hwthread_update_threads(struct rtos *rtos) default: break; } + + threads_found++; } } else { hwthread_fill_thread(rtos, target, threads_found); current_thread = threadid_from_target(target); + threads_found++; } rtos->thread_count = threads_found;