From bf5f21e39a6c04c3845dc61becc90d8602546290 Mon Sep 17 00:00:00 2001 From: oharboe Date: Mon, 24 Aug 2009 07:53:46 +0000 Subject: [PATCH] Steve Grubb fix various and sundry leaks git-svn-id: svn://svn.berlios.de/openocd/trunk@2606 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/helper/command.c | 4 ++++ src/jtag/tcl.c | 18 ++++++++++++++++++ src/jtag/usbprog.c | 1 + src/server/telnet_server.c | 1 + src/svf/svf.c | 2 ++ src/target/embeddedice.c | 1 + src/target/etm.c | 12 ++++++++++++ 7 files changed, 39 insertions(+) diff --git a/src/helper/command.c b/src/helper/command.c index 2737a7b2..d93020e9 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -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; } } diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index ff16a566..defd6ef3 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -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; diff --git a/src/jtag/usbprog.c b/src/jtag/usbprog.c index 5abdf324..6c416644 100644 --- a/src/jtag/usbprog.c +++ b/src/jtag/usbprog.c @@ -435,6 +435,7 @@ struct usbprog_jtag* usbprog_jtag_open(void) } } } + free(tmp); return 0; } diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c index b6b38a0c..f26ad9f6 100644 --- a/src/server/telnet_server.c +++ b/src/server/telnet_server.c @@ -597,6 +597,7 @@ int telnet_init(char *banner) if (telnet_port == 0) { LOG_INFO("telnet port disabled"); + free(telnet_service); return ERROR_OK; } diff --git a/src/svf/svf.c b/src/svf/svf.c index 510b7b0a..16495ac1 100644 --- a/src/svf/svf.c +++ b/src/svf/svf.c @@ -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; } } diff --git a/src/target/embeddedice.c b/src/target/embeddedice.c index 1e003471..0d23c121 100644 --- a/src/target/embeddedice.c +++ b/src/target/embeddedice.c @@ -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; } diff --git a/src/target/etm.c b/src/target/etm.c index 48d2ebaf..2623ebe5 100644 --- a/src/target/etm.c +++ b/src/target/etm.c @@ -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; } -- 2.39.5