memory leaks and missing check on memory allocation.
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
/* find the corresponding flash bank */
retval = get_flash_bank_by_addr(target, run_address, false, &c);
if (retval != ERROR_OK)
- return retval;
+ {
+ goto done;
+ }
if (c == NULL)
{
section++; /* and skip it */
if (run_address + run_size - 1 > c->base + c->size - 1)
{
LOG_ERROR("The image is too big for the flash");
- return ERROR_FAIL;
+ retval = ERROR_FAIL;
+ goto done;
}
/* If we're applying any sector automagic, then pad this
/* allocate buffer */
buffer = malloc(run_size);
+ if (buffer == NULL)
+ {
+ LOG_ERROR("Out of memory for flash bank buffer");
+ retval = ERROR_FAIL;
+ goto done;
+ }
buffer_size = 0;
/* read sections to the buffer */