]> git.sur5r.net Git - openocd/commitdiff
build: fix memory leaks
authorSpencer Oliver <spen@spen-soft.co.uk>
Mon, 13 Aug 2012 10:22:35 +0000 (11:22 +0100)
committerFreddie Chopin <freddie.chopin@gmail.com>
Fri, 24 Aug 2012 16:49:56 +0000 (16:49 +0000)
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>
src/flash/mflash.c
src/flash/nand/lpc3180.c
src/flash/nor/at91sam7.c
src/rtos/FreeRTOS.c
src/rtos/linux.c
src/rtos/rtos.c
src/server/gdb_server.c

index bf61a11495fdf3d319bea530eb4f1a58072230d5..5d1f3b6ed88cb3baf27ce7ea44d3497201316915 100644 (file)
@@ -770,6 +770,7 @@ COMMAND_HANDLER(mg_write_cmd)
        int retval = fileio_size(&fileio, &filesize);
        if (retval != ERROR_OK) {
                fileio_close(&fileio);
+               free(buffer);
                return retval;
        }
 
index 1b5306701b66e256cbde8ab4a8f40b71de56739b..a44f3c21e23e2282a71ee6dd6aaaf031c93112c3 100644 (file)
@@ -524,8 +524,9 @@ static int lpc3180_write_page(struct nand_device *nand,
                        target_write_u32(target, 0x200b8010, 0x0);
 
                        if (!lpc3180_controller_ready(nand, 1000)) {
-                               LOG_ERROR(
-                                       "timeout while waiting for completion of auto encode cycle");
+                               LOG_ERROR("timeout while waiting for completion of auto encode cycle");
+                               free(page_buffer);
+                               free(oob_buffer);
                                return ERROR_NAND_OPERATION_FAILED;
                        }
                }
@@ -536,11 +537,15 @@ static int lpc3180_write_page(struct nand_device *nand,
                retval = nand_read_status(nand, &status);
                if (retval != ERROR_OK) {
                        LOG_ERROR("couldn't read status");
+                       free(page_buffer);
+                       free(oob_buffer);
                        return ERROR_NAND_OPERATION_FAILED;
                }
 
                if (status & NAND_STATUS_FAIL) {
                        LOG_ERROR("write operation didn't pass, status: 0x%2.2x", status);
+                       free(page_buffer);
+                       free(oob_buffer);
                        return ERROR_NAND_OPERATION_FAILED;
                }
 
@@ -888,8 +893,9 @@ static int lpc3180_read_page(struct nand_device *nand,
                        target_write_u32(target, 0x200b8014, 0xaa55aa55);
 
                        if (!lpc3180_controller_ready(nand, 1000)) {
-                               LOG_ERROR(
-                                       "timeout while waiting for completion of auto decode cycle");
+                               LOG_ERROR("timeout while waiting for completion of auto decode cycle");
+                               free(page_buffer);
+                               free(oob_buffer);
                                return ERROR_NAND_OPERATION_FAILED;
                        }
 
@@ -899,6 +905,8 @@ static int lpc3180_read_page(struct nand_device *nand,
                                if (mlc_isr & 0x40) {
                                        LOG_ERROR("uncorrectable error detected: 0x%2.2x",
                                                (unsigned)mlc_isr);
+                                       free(page_buffer);
+                                       free(oob_buffer);
                                        return ERROR_NAND_OPERATION_FAILED;
                                }
 
index 3e99c4a6478f2b84ced89a5dd171141f43bde622..95ba084b5e1d41b827ffa490e9c8ecbe0fcc488b 100644 (file)
@@ -897,8 +897,10 @@ static int at91sam7_erase(struct flash_bank *bank, int first, int last)
                for (pos = 0; pos < nbytes; pos++)
                        buffer[pos] = 0xFF;
 
-               if (at91sam7_write(bank, buffer, bank->sectors[first].offset, nbytes) != ERROR_OK)
+               if (at91sam7_write(bank, buffer, bank->sectors[first].offset, nbytes) != ERROR_OK) {
+                       free(buffer);
                        return ERROR_FLASH_OPERATION_FAILED;
+               }
 
                free(buffer);
        }
index a64626989e3bd1310c0b589f7287915ec109fb76..1e4ddc532a51c1c68d905f66548d61f122df718b 100644 (file)
@@ -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;
index cd7ae0437072fde15d4e5920caa4ddb7f6e4d825..15d52366fb83d9fa7a92223cb090c71c69ec0054 100644 (file)
@@ -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, &reg_list,
-                               &reg_list_size) != ERROR_OK)
+                               &reg_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;
        }
index 07e44eae0d5fe2d204b891c5fd91bf94af8bfc88..524e1dacac39c4d2809581a9e6fbd17eae68133d 100644 (file)
@@ -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;
                        }
 
index 1c0ee08fd80dca34876041f83d7c501dece66449..31f814dee255a5763998fd8971cd04fe5c83d4c7 100644 (file)
@@ -1138,6 +1138,7 @@ static int gdb_set_register_packet(struct connection *connection,
 
        if ((unsigned int)chars != strlen(separator + 1)) {
                LOG_ERROR("gdb sent a packet with wrong register size");
+               free(bin_buf);
                return ERROR_SERVER_REMOTE_CLOSED;
        }