target: fix memory leaks on targets based on arm9tdmi

Similarly to the fix for arm926ejs (also base on arm9tdmi), fix
the other targets based on arm9tdmi.
The fix for arm926ejs is tested on SPEAr320 target.

This fix is proposed separately because is not tested on a correct
target device, but tested on SPEAr320 by hacking the target type
and pretending it is the correct one, e.g.:
	sed -i s/arm926ejs/arm920t/ tcl/target/spear3xx.cfg

The memory leaks detected and fixed are:
- arm register cache;
- EmbeddedICE register cache;
- arm_jtag_reset_callback internal data;
- struct <target_type>_common.

Change-Id: I565f9a5bf144a9df78474434d86a64127ef0fbe5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5699
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2020-05-25 11:28:22 +02:00
parent 6a78c8581d
commit 580b8f5da0
7 changed files with 62 additions and 0 deletions

View File

@ -852,6 +852,16 @@ static int arm920t_target_create(struct target *target, Jim_Interp *interp)
return arm920t_init_arch_info(target, arm920t, target->tap);
}
static void arm920t_deinit_target(struct target *target)
{
struct arm *arm = target_to_arm(target);
struct arm920t_common *arm920t = target_to_arm920(target);
arm7_9_deinit(target);
arm_free_reg_cache(arm);
free(arm920t);
}
COMMAND_HANDLER(arm920t_handle_read_cache_command)
{
int retval = ERROR_OK;
@ -1716,6 +1726,7 @@ struct target_type arm920t_target = {
.commands = arm920t_command_handlers,
.target_create = arm920t_target_create,
.init_target = arm9tdmi_init_target,
.deinit_target = arm920t_deinit_target,
.examine = arm7_9_examine,
.check_reset = arm7_9_check_reset,
};

View File

@ -99,6 +99,16 @@ static int arm946e_target_create(struct target *target, Jim_Interp *interp)
return ERROR_OK;
}
static void arm946e_deinit_target(struct target *target)
{
struct arm *arm = target_to_arm(target);
struct arm946e_common *arm946e = target_to_arm946(target);
arm7_9_deinit(target);
arm_free_reg_cache(arm);
free(arm946e);
}
static int arm946e_verify_pointer(struct command_invocation *cmd,
struct arm946e_common *arm946e)
{
@ -776,6 +786,7 @@ struct target_type arm946e_target = {
.commands = arm946e_command_handlers,
.target_create = arm946e_target_create,
.init_target = arm9tdmi_init_target,
.deinit_target = arm946e_deinit_target,
.examine = arm7_9_examine,
.check_reset = arm7_9_check_reset,
};

View File

@ -56,6 +56,16 @@ static int arm966e_target_create(struct target *target, Jim_Interp *interp)
return arm966e_init_arch_info(target, arm966e, target->tap);
}
static void arm966e_deinit_target(struct target *target)
{
struct arm *arm = target_to_arm(target);
struct arm966e_common *arm966e = target_to_arm966(target);
arm7_9_deinit(target);
arm_free_reg_cache(arm);
free(arm966e);
}
static int arm966e_verify_pointer(struct command_invocation *cmd,
struct arm966e_common *arm966e)
{
@ -278,6 +288,7 @@ struct target_type arm966e_target = {
.commands = arm966e_command_handlers,
.target_create = arm966e_target_create,
.init_target = arm9tdmi_init_target,
.deinit_target = arm966e_deinit_target,
.examine = arm7_9_examine,
.check_reset = arm7_9_check_reset,
};

View File

@ -786,6 +786,16 @@ static int arm9tdmi_target_create(struct target *target, Jim_Interp *interp)
return ERROR_OK;
}
void arm9tdmi_deinit_target(struct target *target)
{
struct arm *arm = target_to_arm(target);
struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
arm7_9_deinit(target);
arm_free_reg_cache(arm);
free(arm7_9);
}
COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command)
{
struct target *target = get_current_target(CMD_CTX);
@ -921,6 +931,7 @@ struct target_type arm9tdmi_target = {
.commands = arm9tdmi_command_handlers,
.target_create = arm9tdmi_target_create,
.init_target = arm9tdmi_init_target,
.deinit_target = arm9tdmi_deinit_target,
.examine = arm7_9_examine,
.check_reset = arm7_9_check_reset,
};

View File

@ -26,6 +26,7 @@
int arm9tdmi_init_target(struct command_context *cmd_ctx,
struct target *target);
void arm9tdmi_deinit_target(struct target *target);
int arm9tdmi_init_arch_info(struct target *target,
struct arm7_9_common *arm7_9, struct jtag_tap *tap);
extern const struct command_registration arm9tdmi_command_handlers[];

View File

@ -347,6 +347,16 @@ static int fa526_target_create(struct target *target, Jim_Interp *interp)
return fa526_init_arch_info(target, arm920t, target->tap);
}
static void fa526_deinit_target(struct target *target)
{
struct arm *arm = target_to_arm(target);
struct arm920t_common *arm920t = target_to_arm920(target);
arm7_9_deinit(target);
arm_free_reg_cache(arm);
free(arm920t);
}
/** Holds methods for FA526 targets. */
struct target_type fa526_target = {
.name = "fa526",
@ -383,6 +393,7 @@ struct target_type fa526_target = {
.commands = arm920t_command_handlers,
.target_create = fa526_target_create,
.init_target = arm9tdmi_init_target,
.deinit_target = fa526_deinit_target,
.examine = arm7_9_examine,
.check_reset = arm7_9_check_reset,
};

View File

@ -593,6 +593,11 @@ static int feroceon_init_target(struct command_context *cmd_ctx,
return ERROR_OK;
}
static void feroceon_deinit_target(struct target *target)
{
arm9tdmi_deinit_target(target);
}
static void feroceon_common_setup(struct target *target)
{
struct arm *arm = target->arch_info;
@ -729,6 +734,7 @@ struct target_type feroceon_target = {
.commands = arm926ejs_command_handlers,
.target_create = feroceon_target_create,
.init_target = feroceon_init_target,
.deinit_target = feroceon_deinit_target,
.examine = feroceon_examine,
};