From: Spencer Oliver Date: Mon, 13 Aug 2012 10:31:54 +0000 (+0100) Subject: tcl: fix potential memory leaks X-Git-Tag: v0.6.0-rc2~25 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2d57e80801b605833118e133c79a97b67ace7e93;p=openocd 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 Reviewed-on: http://openocd.zylin.com/776 Tested-by: jenkins Reviewed-by: Freddie Chopin --- diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c index ec80f6ff..cf6fa080 100644 --- a/src/flash/nor/tcl.c +++ b/src/flash/nor/tcl.c @@ -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;