diff options
author | Tomas Vanek <vanekt@fbl.cz> | 2019-01-31 14:21:56 +0100 |
---|---|---|
committer | Tomas Vanek <vanekt@fbl.cz> | 2019-02-07 08:03:18 +0000 |
commit | 9f021c2bc129f8f7c659c64ad19531bd8073264a (patch) | |
tree | 174b9cd99d1d5385a1156f10b822d31e985f74b7 /src/target/cortex_m.c | |
parent | 96903e6df43e2bc967267e034edf15a7c274d044 (diff) | |
download | riscv-openocd-9f021c2bc129f8f7c659c64ad19531bd8073264a.zip riscv-openocd-9f021c2bc129f8f7c659c64ad19531bd8073264a.tar.gz riscv-openocd-9f021c2bc129f8f7c659c64ad19531bd8073264a.tar.bz2 |
target/cortex_m: fix clang static analyzer warning
Fix "Potential leak of memory pointed to by 'cortex_m'"
and test for NULL return from calloc in cortex_m_target_create()
Change-Id: I4d2bb5bccc57f0ed60696f3d588297a858b8ea60
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4881
Tested-by: jenkins
Reviewed-by: Moritz Fischer <moritz.fischer@ettus.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src/target/cortex_m.c')
-rw-r--r-- | src/target/cortex_m.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index 34a19e7..62d3760 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -2276,14 +2276,19 @@ static int cortex_m_init_arch_info(struct target *target, static int cortex_m_target_create(struct target *target, Jim_Interp *interp) { - struct cortex_m_common *cortex_m = calloc(1, sizeof(struct cortex_m_common)); - cortex_m->common_magic = CORTEX_M_COMMON_MAGIC; struct adiv5_private_config *pc; pc = (struct adiv5_private_config *)target->private_config; if (adiv5_verify_config(pc) != ERROR_OK) return ERROR_FAIL; + struct cortex_m_common *cortex_m = calloc(1, sizeof(struct cortex_m_common)); + if (cortex_m == NULL) { + LOG_ERROR("No memory creating target"); + return ERROR_FAIL; + } + + cortex_m->common_magic = CORTEX_M_COMMON_MAGIC; cortex_m->apsel = pc->ap_num; cortex_m_init_arch_info(target, cortex_m, pc->dap); |