target/arm_dap: fix memory leak in error path of dap_create()

Change-Id: I91fa5910670161b62a76fc834b6394c5a6c05395
Suggested-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6685
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Tomas Vanek 2021-11-10 12:46:42 +01:00 committed by Antonio Borneo
parent 08dac883a1
commit 3eef83e4bd
1 changed files with 4 additions and 1 deletions

View File

@ -267,8 +267,11 @@ static int dap_create(struct jim_getopt_info *goi)
dap_commands[0].chain = NULL;
e = register_commands_with_data(cmd_ctx, NULL, dap_commands, dap);
if (e != ERROR_OK)
if (e != ERROR_OK) {
free(dap->name);
free(dap);
return JIM_ERR;
}
list_add_tail(&dap->lh, &all_dap);