target/arm_dap: fix memory leak in error path of dap_create()
[fw/openocd] / src / target / arm_dap.c
index 94edfc09d14116859955ffc3a263b5aad612b71d..18e77b50fe1b851bb7ea814efcc9a26da3d1c923 100644 (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);