summaryrefslogtreecommitdiff
path: root/src/flash
diff options
context:
space:
mode:
Diffstat (limited to 'src/flash')
-rw-r--r--src/flash/flash.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/flash/flash.c b/src/flash/flash.c
index 03ee46f3..390e37ad 100644
--- a/src/flash/flash.c
+++ b/src/flash/flash.c
@@ -570,10 +570,19 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
failed = malloc(sizeof(int) * image.num_sections);
- if ((retval = flash_write(target, &image, &written, &error_str, failed, auto_erase)) != ERROR_OK)
+ error_str=NULL;
+ retval = flash_write(target, &image, &written, &error_str, failed, auto_erase);
+
+ if (retval != ERROR_OK)
{
- command_print(cmd_ctx, "failed writing image %s: %s", args[0], error_str);
- free(error_str);
+ if (error_str)
+ {
+ command_print(cmd_ctx, "failed writing image %s: %s", args[0], error_str);
+ free(error_str);
+ }
+ image_close(&image);
+ free(failed);
+ return retval;
}
for (i = 0; i < image.num_sections; i++)
@@ -938,3 +947,4 @@ int handle_flash_auto_erase_command(struct command_context_s *cmd_ctx, char *cmd
return ERROR_OK;
}
+