]> git.sur5r.net Git - openocd/commitdiff
Steve Grubb <sgrubb@redhat.com> fix various and sundry leaks
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Mon, 24 Aug 2009 07:53:46 +0000 (07:53 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Mon, 24 Aug 2009 07:53:46 +0000 (07:53 +0000)
git-svn-id: svn://svn.berlios.de/openocd/trunk@2606 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/helper/command.c
src/jtag/tcl.c
src/jtag/usbprog.c
src/server/telnet_server.c
src/svf/svf.c
src/target/embeddedice.c
src/target/etm.c

index 2737a7b23f7d26f2ce43a9d37a6c37bdb185d126..d93020e990055665d3f0909a5d0f766c929ede3f 100644 (file)
@@ -117,6 +117,10 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                words[i] = strdup(w);
                if (words[i] == NULL)
                {
+                       int j;
+                       for (j = 0; j < i; j++)
+                               free(words[j]);
+                       free(words);
                        return JIM_ERR;
                }
        }
index ff16a56647831ce837d6b8272998b58734aa77a3..defd6ef389cf02f4772e292b32eab98f728c1214 100644 (file)
@@ -220,6 +220,7 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
         * */
        if (goi->argc < 3) {
                Jim_SetResult_sprintf(goi->interp, "Missing CHIP TAP OPTIONS ....");
+               free(pTap);
                return JIM_ERR;
        }
        Jim_GetOpt_String(goi, &cp, NULL);
@@ -249,6 +250,8 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
                e = Jim_GetOpt_Nvp(goi, opts, &n);
                if (e != JIM_OK) {
                        Jim_GetOpt_NvpUnknown(goi, opts, 0);
+                       free((void *)pTap->dotted_name);
+                       free(pTap);
                        return e;
                }
                LOG_DEBUG("Processing option: %s", n->name);
@@ -266,12 +269,16 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
                        e = Jim_GetOpt_Wide(goi, &w);
                        if (e != JIM_OK) {
                                Jim_SetResult_sprintf(goi->interp, "option: %s bad parameter", n->name);
+                               free((void *)pTap->dotted_name);
+                               free(pTap);
                                return e;
                        }
 
                        new_expected_ids = malloc(sizeof(uint32_t) * (pTap->expected_ids_cnt + 1));
                        if (new_expected_ids == NULL) {
                                Jim_SetResult_sprintf(goi->interp, "no memory");
+                               free((void *)pTap->dotted_name);
+                               free(pTap);
                                return JIM_ERR;
                        }
 
@@ -290,6 +297,8 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
                        e = Jim_GetOpt_Wide(goi, &w);
                        if (e != JIM_OK) {
                                Jim_SetResult_sprintf(goi->interp, "option: %s bad parameter", n->name);
+                               free((void *)pTap->dotted_name);
+                               free(pTap);
                                return e;
                        }
                        switch (n->value) {
@@ -303,6 +312,8 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
                                if (is_bad_irval(pTap->ir_length, w)) {
                                        LOG_ERROR("IR mask %x too big",
                                                        (int) w);
+                                       free((void *)pTap->dotted_name);
+                                       free(pTap);
                                        return ERROR_FAIL;
                                }
                                pTap->ir_capture_mask = w;
@@ -312,6 +323,8 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
                                if (is_bad_irval(pTap->ir_length, w)) {
                                        LOG_ERROR("IR capture %x too big",
                                                        (int) w);
+                                       free((void *)pTap->dotted_name);
+                                       free(pTap);
                                        return ERROR_FAIL;
                                }
                                pTap->ir_capture_value = w;
@@ -1144,7 +1157,12 @@ static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, c
                tap = jtag_tap_by_string(args[i*2]);
                if (tap == NULL)
                {
+                       int j;
+                       for (j = 0; j < i; j++)
+                               free(fields[j].out_value);
+                        free(fields);
                        command_print(cmd_ctx, "Tap: %s unknown", args[i*2]);
+
                        return ERROR_FAIL;
                }
                int field_size = tap->ir_length;
index 5abdf3243d44816c89912091b1595dda92a90823..6c416644bff9e12405ce247fea9583e3b3db1584 100644 (file)
@@ -435,6 +435,7 @@ struct usbprog_jtag* usbprog_jtag_open(void)
                        }
                }
        }
+       free(tmp);
        return 0;
 }
 
index b6b38a0cf56afa842ce56291477e5dd43188acf8..f26ad9f6717ad555efaecbb3e93ddfc9c4a74241 100644 (file)
@@ -597,6 +597,7 @@ int telnet_init(char *banner)
        if (telnet_port == 0)
        {
                LOG_INFO("telnet port disabled");
+               free(telnet_service);
                return ERROR_OK;
        }
 
index 510b7b0afa2bc65891c6e6e3d13c8443bfa859ae..16495ac140d1f92ea862bf65037afafca101cb06 100644 (file)
@@ -1322,6 +1322,7 @@ static int svf_run_command(struct command_context_s *cmd_ctx, char *cmd_str)
                                if (!svf_tap_state_is_valid(path[i]))
                                {
                                        LOG_ERROR("%s is not valid state", svf_tap_state_name[path[i]]);
+                                       free(path);
                                        return ERROR_FAIL;
                                }
                                if (TAP_RESET == path[i])
@@ -1348,6 +1349,7 @@ static int svf_run_command(struct command_context_s *cmd_ctx, char *cmd_str)
                                else
                                {
                                        LOG_ERROR("%s is not valid state", svf_tap_state_name[path[num_of_argu - 1]]);
+                                       free(path);
                                        return ERROR_FAIL;
                                }
                        }
index 1e00347135335b0a9dd621ef7440c95bdfc76ffe..0d23c121481d7d1929ee6ee1e5a10b82c96a419c 100644 (file)
@@ -197,6 +197,7 @@ reg_cache_t* embeddedice_build_reg_cache(target_t *target, arm7_9_common_t *arm7
                        free(reg_list[i].value);
                }
                free(reg_list);
+               free(reg_cache);
                free(arch_info);
                return NULL;
        }
index 48d2ebaf3a1150001faba2ec4e115d80eef868ec..2623ebe53fb41a77f31320fda155b01754346433 100644 (file)
@@ -246,6 +246,12 @@ reg_cache_t* etm_build_reg_cache(target_t *target, arm_jtag_t *jtag_info, etm_co
                if (!etb)
                {
                        LOG_ERROR("etb selected as etm capture driver, but no ETB configured");
+                       for (i = 0; i < num_regs; i++)
+                       {
+                               free(reg_list[i].value);
+                       }
+                       free(reg_cache);
+                       free(arch_info);
                        return ERROR_OK;
                }
 
@@ -1202,6 +1208,7 @@ static int handle_etm_config_command(struct command_context_s *cmd_ctx, char *cm
 
        if (argc != 5)
        {
+               free(etm_ctx);
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
@@ -1209,12 +1216,14 @@ static int handle_etm_config_command(struct command_context_s *cmd_ctx, char *cm
        if (!target)
        {
                LOG_ERROR("target '%s' not defined", args[0]);
+               free(etm_ctx);
                return ERROR_FAIL;
        }
 
        if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
+               free(etm_ctx);
                return ERROR_FAIL;
        }
 
@@ -1231,6 +1240,7 @@ static int handle_etm_config_command(struct command_context_s *cmd_ctx, char *cm
                        break;
                default:
                        command_print(cmd_ctx, "unsupported ETM port width '%s', must be 4, 8 or 16", args[1]);
+                       free(etm_ctx);
                        return ERROR_FAIL;
        }
 
@@ -1249,6 +1259,7 @@ static int handle_etm_config_command(struct command_context_s *cmd_ctx, char *cm
        else
        {
                command_print(cmd_ctx, "unsupported ETM port mode '%s', must be 'normal', 'multiplexed' or 'demultiplexed'", args[2]);
+               free(etm_ctx);
                return ERROR_FAIL;
        }
 
@@ -1263,6 +1274,7 @@ static int handle_etm_config_command(struct command_context_s *cmd_ctx, char *cm
        else
        {
                command_print(cmd_ctx, "unsupported ETM port clocking '%s', must be 'full' or 'half'", args[3]);
+               free(etm_ctx);
                return ERROR_FAIL;
        }