diff --git a/src/target/arm.h b/src/target/arm.h index b39957495..3450260f0 100644 --- a/src/target/arm.h +++ b/src/target/arm.h @@ -272,6 +272,8 @@ struct arm_reg { }; struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm); +void arm_free_reg_cache(struct arm *arm); + struct reg_cache *armv8_build_reg_cache(struct target *target); extern const struct command_registration arm_command_handlers[]; diff --git a/src/target/arm_dpm.c b/src/target/arm_dpm.c index 495d63ec2..72215f90b 100644 --- a/src/target/arm_dpm.c +++ b/src/target/arm_dpm.c @@ -1100,6 +1100,7 @@ int arm_dpm_setup(struct arm_dpm *dpm) dpm->dwp = calloc(dpm->nwp, sizeof(*dpm->dwp)); if (!dpm->dbp || !dpm->dwp) { + arm_free_reg_cache(arm); free(dpm->dbp); free(dpm->dwp); return ERROR_FAIL; diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c index b4581d5f1..58bc3390a 100644 --- a/src/target/armv4_5.c +++ b/src/target/armv4_5.c @@ -769,6 +769,27 @@ struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm) return cache; } +void arm_free_reg_cache(struct arm *arm) +{ + if (!arm || !arm->core_cache) + return; + + struct reg_cache *cache = arm->core_cache; + + for (unsigned int i = 0; i < cache->num_regs; i++) { + struct reg *reg = &cache->reg_list[i]; + + free(reg->feature); + free(reg->reg_data_type); + } + + free(cache->reg_list[0].arch_info); + free(cache->reg_list); + free(cache); + + arm->core_cache = NULL; +} + int arm_arch_state(struct target *target) { struct arm *arm = target_to_arm(target); diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index f71b15524..f562a7614 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -2959,6 +2959,7 @@ static void cortex_a_deinit_target(struct target *target) } free(cortex_a->brp_list); + arm_free_reg_cache(dpm->arm); free(dpm->dbp); free(dpm->dwp); free(target->private_config);