From: Tim Newsome Date: Thu, 27 Jan 2022 18:00:06 +0000 (-0800) Subject: Fix small memory leak. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=2c0a65baa2f17a15fcb5bb014e5dda33fecddaf8;p=fw%2Fopenocd Fix small memory leak. See https://github.com/riscv/riscv-openocd/pull/672 Change-Id: Ia11ab9bcf860f770ea64ad867102c74b898f6b66 Signed-off-by: Tim Newsome Reviewed-on: https://review.openocd.org/c/openocd/+/6831 Tested-by: jenkins Reviewed-by: zapb Reviewed-by: Antonio Borneo --- diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 7af460241..2b9179d53 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -2308,9 +2308,11 @@ static int init_target(struct command_context *cmd_ctx, generic_info->hart_count = &riscv013_hart_count; generic_info->data_bits = &riscv013_data_bits; generic_info->print_info = &riscv013_print_info; - generic_info->version_specific = calloc(1, sizeof(riscv013_info_t)); - if (!generic_info->version_specific) - return ERROR_FAIL; + if (!generic_info->version_specific) { + generic_info->version_specific = calloc(1, sizeof(riscv013_info_t)); + if (!generic_info->version_specific) + return ERROR_FAIL; + } generic_info->sample_memory = sample_memory; riscv013_info_t *info = get_info(target);