target/arm7tdmi: fix memory leak of register cache 96/5696/4
authorAntonio Borneo <borneo.antonio@gmail.com>
Mon, 25 May 2020 08:58:40 +0000 (10:58 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 26 Jul 2020 19:12:48 +0000 (20:12 +0100)
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 <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5696
Tested-by: jenkins
src/target/arm7tdmi.c
src/target/arm7tdmi.h

index e1e91c3a04b71fd6cccf4a12e61367b062087652..01685ab6a4a577901cb6693135b30cadeaca2742 100644 (file)
@@ -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,
 };
index 053f64df8ea13b1bfacfc7a6de4fead9705108fe..3cc3d4a7b456351e2cd145948cf1b1bc9b2a0822 100644 (file)
@@ -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 */

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)