From: OpenOCD-Gerrit <ope...@us...> - 2020-07-26 19:13:18
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 19aa77cc7fc369af2da9ca1b1539161284f90286 (commit) via df1dcc27eeb3a42d3dd9708c9518a2230242f746 (commit) via 580b8f5da015f49b5ca939ed4fd928b8d941944e (commit) from 6a78c8581d81665969f24563faccd220de517961 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 19aa77cc7fc369af2da9ca1b1539161284f90286 Author: Antonio Borneo <bor...@gm...> Date: Mon May 25 10:58:40 2020 +0200 target/arm7tdmi: fix memory leak of register cache There is no method to free the register cache, allocated in arm7tdmi_init_target(), so we get a memory leak. Issue identified by tracking all calls to arm_build_reg_cache(). Implement the method arm7tdmi_deinit_target() that in turn calls arm7tdmi_free_reg_cache(). NOT TESTED on a real arm7tdmi target. Tested on a arm926ejs (SPEAr320) by hacking the target type and pretending it is a arm7tdmi: sed -i s/arm926ejs/arm7tdmi/ tcl/target/spear3xx.cfg Change-Id: Iad465b708eb4ebb298725d7155fea76357e9045c Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/5696 Tested-by: jenkins diff --git a/src/target/arm7tdmi.c b/src/target/arm7tdmi.c index e1e91c3a0..01685ab6a 100644 --- a/src/target/arm7tdmi.c +++ b/src/target/arm7tdmi.c @@ -613,6 +613,13 @@ static void arm7tdmi_build_reg_cache(struct target *target) (*cache_p) = arm_build_reg_cache(target, arm); } +static void arm7tdmi_free_reg_cache(struct target *target) +{ + struct arm *arm = target_to_arm(target); + + arm_free_reg_cache(arm); +} + int arm7tdmi_init_target(struct command_context *cmd_ctx, struct target *target) { arm7tdmi_build_reg_cache(target); @@ -620,6 +627,11 @@ int arm7tdmi_init_target(struct command_context *cmd_ctx, struct target *target) return ERROR_OK; } +void arm7tdmi_deinit_target(struct target *target) +{ + arm7tdmi_free_reg_cache(target); +} + int arm7tdmi_init_arch_info(struct target *target, struct arm7_9_common *arm7_9, struct jtag_tap *tap) { @@ -718,6 +730,7 @@ struct target_type arm7tdmi_target = { .commands = arm7_9_command_handlers, .target_create = arm7tdmi_target_create, .init_target = arm7tdmi_init_target, + .deinit_target = arm7tdmi_deinit_target, .examine = arm7_9_examine, .check_reset = arm7_9_check_reset, }; diff --git a/src/target/arm7tdmi.h b/src/target/arm7tdmi.h index 053f64df8..3cc3d4a7b 100644 --- a/src/target/arm7tdmi.h +++ b/src/target/arm7tdmi.h @@ -28,5 +28,6 @@ int arm7tdmi_init_arch_info(struct target *target, struct arm7_9_common *arm7_9, struct jtag_tap *tap); int arm7tdmi_init_target(struct command_context *cmd_ctx, struct target *target); +void arm7tdmi_deinit_target(struct target *target); #endif /* OPENOCD_TARGET_ARM7TDMI_H */ commit df1dcc27eeb3a42d3dd9708c9518a2230242f746 Author: Antonio Borneo <bor...@gm...> Date: Mon May 25 10:43:53 2020 +0200 target/xscale: fix memory leak of register cache There is no method to free the register cache, allocated in xscale_build_reg_cache(), so we get a memory leak. Issue identified by tracking all calls to arm_build_reg_cache(). Implement the method xscale_deinit_target() that in turn calls the new xscale_free_reg_cache(). Fix leak of struct xscale. NOT TESTED on a real xscale target. Tested on a arm926ejs (SPEAr320) by hacking the target type and pretending it is a xscale: sed -i s/arm926ejs/xscale/ tcl/target/spear3xx.cfg Change-Id: Ibb2104c42411b76f4bb77c2fa387d1b85a3d2d5d Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/5695 Tested-by: jenkins diff --git a/src/target/xscale.c b/src/target/xscale.c index edab4f9fc..1bca96d73 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -2903,6 +2903,21 @@ static void xscale_build_reg_cache(struct target *target) xscale->reg_cache = (*cache_p); } +static void xscale_free_reg_cache(struct target *target) +{ + struct xscale_common *xscale = target_to_xscale(target); + struct reg_cache *cache = xscale->reg_cache; + + for (unsigned int i = 0; i < ARRAY_SIZE(xscale_reg_arch_info); i++) + free(cache->reg_list[i].value); + + free(cache->reg_list[0].arch_info); + free(cache->reg_list); + free(cache); + + arm_free_reg_cache(&xscale->arm); +} + static int xscale_init_target(struct command_context *cmd_ctx, struct target *target) { @@ -2910,6 +2925,14 @@ static int xscale_init_target(struct command_context *cmd_ctx, return ERROR_OK; } +static void xscale_deinit_target(struct target *target) +{ + struct xscale_common *xscale = target_to_xscale(target); + + xscale_free_reg_cache(target); + free(xscale); +} + static int xscale_init_arch_info(struct target *target, struct xscale_common *xscale, struct jtag_tap *tap) { @@ -3725,6 +3748,7 @@ struct target_type xscale_target = { .commands = xscale_command_handlers, .target_create = xscale_target_create, .init_target = xscale_init_target, + .deinit_target = xscale_deinit_target, .virt2phys = xscale_virt2phys, .mmu = xscale_mmu commit 580b8f5da015f49b5ca939ed4fd928b8d941944e Author: Antonio Borneo <bor...@gm...> Date: Mon May 25 11:28:22 2020 +0200 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 <bor...@gm...> Reviewed-on: http://openocd.zylin.com/5699 Tested-by: jenkins diff --git a/src/target/arm920t.c b/src/target/arm920t.c index 3ddd19888..c96975a77 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -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, }; diff --git a/src/target/arm946e.c b/src/target/arm946e.c index 4ef167a9d..6b187f3ff 100644 --- a/src/target/arm946e.c +++ b/src/target/arm946e.c @@ -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, }; diff --git a/src/target/arm966e.c b/src/target/arm966e.c index 8462f546e..8ddcb3c79 100644 --- a/src/target/arm966e.c +++ b/src/target/arm966e.c @@ -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, }; diff --git a/src/target/arm9tdmi.c b/src/target/arm9tdmi.c index 6ab06edf9..4810c2b16 100644 --- a/src/target/arm9tdmi.c +++ b/src/target/arm9tdmi.c @@ -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, }; diff --git a/src/target/arm9tdmi.h b/src/target/arm9tdmi.h index c6f0ccf0f..56946f78a 100644 --- a/src/target/arm9tdmi.h +++ b/src/target/arm9tdmi.h @@ -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[]; diff --git a/src/target/fa526.c b/src/target/fa526.c index bb9f7353a..aa9e45043 100644 --- a/src/target/fa526.c +++ b/src/target/fa526.c @@ -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, }; diff --git a/src/target/feroceon.c b/src/target/feroceon.c index 4a6c6dcf0..d2b707d44 100644 --- a/src/target/feroceon.c +++ b/src/target/feroceon.c @@ -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, }; ----------------------------------------------------------------------- Summary of changes: src/target/arm7tdmi.c | 13 +++++++++++++ src/target/arm7tdmi.h | 1 + src/target/arm920t.c | 11 +++++++++++ src/target/arm946e.c | 11 +++++++++++ src/target/arm966e.c | 11 +++++++++++ src/target/arm9tdmi.c | 11 +++++++++++ src/target/arm9tdmi.h | 1 + src/target/fa526.c | 11 +++++++++++ src/target/feroceon.c | 6 ++++++ src/target/xscale.c | 24 ++++++++++++++++++++++++ 10 files changed, 100 insertions(+) hooks/post-receive -- Main OpenOCD repository |