diff options
author | Spencer Oliver <spen@spen-soft.co.uk> | 2012-08-13 11:22:35 +0100 |
---|---|---|
committer | Freddie Chopin <freddie.chopin@gmail.com> | 2012-08-24 16:49:56 +0000 |
commit | 60a932b36804bff8b6ca40adc665a33a59475db1 (patch) | |
tree | e3a087a3aa6fe883aea25d7f95d5bb05cce68fcd /src/rtos | |
parent | fb525cdd76982b1abf69974f3ed9327876df0036 (diff) | |
download | riscv-openocd-60a932b36804bff8b6ca40adc665a33a59475db1.zip riscv-openocd-60a932b36804bff8b6ca40adc665a33a59475db1.tar.gz riscv-openocd-60a932b36804bff8b6ca40adc665a33a59475db1.tar.bz2 |
build: fix memory leaks
Fix the memory leaks found by clang-3.1
Change-Id: Iaae68627ef599c324c9c9ee5737c22e92512862d
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/775
Tested-by: jenkins
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
Diffstat (limited to 'src/rtos')
-rw-r--r-- | src/rtos/FreeRTOS.c | 18 | ||||
-rw-r--r-- | src/rtos/linux.c | 21 | ||||
-rw-r--r-- | src/rtos/rtos.c | 2 |
3 files changed, 29 insertions, 12 deletions
diff --git a/src/rtos/FreeRTOS.c b/src/rtos/FreeRTOS.c index a646269..1e4ddc5 100644 --- a/src/rtos/FreeRTOS.c +++ b/src/rtos/FreeRTOS.c @@ -259,6 +259,7 @@ static int FreeRTOS_update_threads(struct rtos *rtos) (uint8_t *)&list_thread_count); if (retval != ERROR_OK) { LOG_OUTPUT("Error reading number of threads in FreeRTOS thread list\r\n"); + free(list_of_lists); return retval; } @@ -273,8 +274,8 @@ static int FreeRTOS_update_threads(struct rtos *rtos) param->pointer_width, (uint8_t *)&list_elem_ptr); if (retval != ERROR_OK) { - LOG_OUTPUT( - "Error reading first thread item location in FreeRTOS thread list\r\n"); + LOG_OUTPUT("Error reading first thread item location in FreeRTOS thread list\r\n"); + free(list_of_lists); return retval; } @@ -288,8 +289,8 @@ static int FreeRTOS_update_threads(struct rtos *rtos) param->pointer_width, (uint8_t *)&(rtos->thread_details[tasks_found].threadid)); if (retval != ERROR_OK) { - LOG_OUTPUT( - "Error reading thread list item object in FreeRTOS thread list\r\n"); + LOG_OUTPUT("Error reading thread list item object in FreeRTOS thread list\r\n"); + free(list_of_lists); return retval; } @@ -304,8 +305,8 @@ static int FreeRTOS_update_threads(struct rtos *rtos) FREERTOS_THREAD_NAME_STR_SIZE, (uint8_t *)&tmp_str); if (retval != ERROR_OK) { - LOG_OUTPUT( - "Error reading first thread item location in FreeRTOS thread list\r\n"); + LOG_OUTPUT("Error reading first thread item location in FreeRTOS thread list\r\n"); + free(list_of_lists); return retval; } tmp_str[FREERTOS_THREAD_NAME_STR_SIZE-1] = '\x00'; @@ -338,12 +339,13 @@ static int FreeRTOS_update_threads(struct rtos *rtos) param->pointer_width, (uint8_t *)&list_elem_ptr); if (retval != ERROR_OK) { - LOG_OUTPUT( - "Error reading next thread item location in FreeRTOS thread list\r\n"); + LOG_OUTPUT("Error reading next thread item location in FreeRTOS thread list\r\n"); + free(list_of_lists); return retval; } } } + free(list_of_lists); rtos->thread_count = tasks_found; return 0; diff --git a/src/rtos/linux.c b/src/rtos/linux.c index cd7ae04..15d5236 100644 --- a/src/rtos/linux.c +++ b/src/rtos/linux.c @@ -420,6 +420,8 @@ int fill_task(struct target *target, struct threads *t) } else LOG_ERROR("fill task: unable to read memory"); + free(buffer); + return retval; } @@ -494,8 +496,10 @@ int get_current(struct target *target, int create) int retval; if (target_get_gdb_reg_list(head->target, ®_list, - ®_list_size) != ERROR_OK) + ®_list_size) != ERROR_OK) { + free(buffer); return ERROR_TARGET_FAILURE; + } if (!reg_list[13]->valid) reg_list[13]->type->get(reg_list[13]); @@ -550,6 +554,8 @@ int get_current(struct target *target, int create) head = head->next; } + free(buffer); + return ERROR_OK; } @@ -615,6 +621,7 @@ retry: (uint8_t *) registers); if (retval != ERROR_OK) { + free(buffer); LOG_ERROR("cpu_context: unable to read memory\n"); return context; } @@ -643,6 +650,8 @@ retry: if (*thread_info_addr_old == 0xdeadbeef) *thread_info_addr_old = thread_info_addr_update; + free(buffer); + return context; } @@ -655,11 +664,13 @@ uint32_t next_task(struct target *target, struct threads *t) if (retval == ERROR_OK) { uint32_t val = get_buffer(target, buffer); val = val - NEXT; - return val; free(buffer); + return val; } else LOG_ERROR("next task: unable to read memory"); + free(buffer); + return 0; } @@ -778,6 +789,7 @@ int linux_get_tasks(struct target *target, int context) retval = get_name(target, t); if (loop > MAX_THREADS) { + free(t); LOG_INFO("more than %d threads !!", MAX_THREADS); return ERROR_FAIL; } @@ -829,6 +841,7 @@ int linux_get_tasks(struct target *target, int context) (timeval_ms() - start) / linux_os->threadid_count); LOG_INFO("threadid count %d", linux_os->threadid_count); + free(t); return ERROR_OK; } @@ -973,7 +986,7 @@ error_handling: #ifndef PID_CHECK error_handling: free(t); - LOG_ERROR("unable toread pid"); + LOG_ERROR("unable to read pid"); return; #endif @@ -1454,7 +1467,7 @@ static int linux_thread_packet(struct connection *connection, char *packet, } } - /* if a packet handler returned an error, exit input loop */ + /* if a packet handler returned an error, exit input loop */ if (retval != ERROR_OK) return retval; } diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index 07e44ea..524e1da 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -169,6 +169,8 @@ int rtos_qsymbol(struct connection *connection, char *packet, int packet_size) if (target->rtos->symbols[symbol_num].symbol_name == NULL) { LOG_OUTPUT("ERROR: unknown symbol\r\n"); gdb_put_packet(connection, "OK", 2); + free(hex_name_str); + free(name_str); return ERROR_OK; } |