From 3eef83e4bd2b112b98d73f8b0947af93c193e0ef Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Wed, 10 Nov 2021 12:46:42 +0100 Subject: [PATCH] target/arm_dap: fix memory leak in error path of dap_create() Change-Id: I91fa5910670161b62a76fc834b6394c5a6c05395 Suggested-by: Antonio Borneo Signed-off-by: Tomas Vanek Reviewed-on: https://review.openocd.org/c/openocd/+/6685 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/arm_dap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/target/arm_dap.c b/src/target/arm_dap.c index 94edfc09d..18e77b50f 100644 --- a/src/target/arm_dap.c +++ b/src/target/arm_dap.c @@ -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);