From 7cc79a8d62e0c98b52de04f71ef04167b8055385 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 2 Jun 2022 11:17:49 +0200 Subject: [PATCH] arm_adi_v5: check for calloc() return value In function adiv5_jim_configure() check that calloc() returns a valid allocated memory pointer. Change-Id: I97287e168834693900341add9d9eb9a5f38c55b4 Signed-off-by: Antonio Borneo Reported-by: Tomas Vanek Reviewed-on: https://review.openocd.org/c/openocd/+/7014 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/arm_adi_v5.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index 52b12cb93..4d5f02b32 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -2044,6 +2044,10 @@ int adiv5_jim_configure(struct target *target, struct jim_getopt_info *goi) pc = (struct adiv5_private_config *)target->private_config; if (!pc) { pc = calloc(1, sizeof(struct adiv5_private_config)); + if (!pc) { + LOG_ERROR("Out of memory"); + return JIM_ERR; + } pc->ap_num = DP_APSEL_INVALID; target->private_config = pc; }