Browse Source

tcl: fix potential memory leaks

Reorder to allocate all memory after COMMAND_PARSE_NUMBER call.
This removes a clang warning about un-released memory

Change-Id: I8dbeb664a6467077157015bd879bc0aefc5e8614
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/776
Tested-by: jenkins
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
tags/v0.6.0-rc2
Spencer Oliver 10 years ago
committed by Freddie Chopin
parent
commit
2d57e80801
1 changed files with 11 additions and 10 deletions
  1. +11
    -10
      src/flash/nor/tcl.c

+ 11
- 10
src/flash/nor/tcl.c View File

@@ -427,16 +427,7 @@ COMMAND_HANDLER(handle_flash_fill_command)
int retval = ERROR_OK;

static size_t const chunksize = 1024;
uint8_t *chunk = malloc(chunksize);
if (chunk == NULL)
return ERROR_FAIL;

uint8_t *readback = malloc(chunksize);
if (readback == NULL) {
free(chunk);
return ERROR_FAIL;
}

uint8_t *chunk = NULL, *readback = NULL;

if (CMD_ARGC != 3) {
retval = ERROR_COMMAND_SYNTAX_ERROR;
@@ -447,6 +438,16 @@ COMMAND_HANDLER(handle_flash_fill_command)
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], pattern);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], count);

chunk = malloc(chunksize);
if (chunk == NULL)
return ERROR_FAIL;

readback = malloc(chunksize);
if (readback == NULL) {
free(chunk);
return ERROR_FAIL;
}

if (count == 0)
goto done;



Loading…
Cancel
Save