From 2d57e80801b605833118e133c79a97b67ace7e93 Mon Sep 17 00:00:00 2001 From: Spencer Oliver Date: Mon, 13 Aug 2012 11:31:54 +0100 Subject: [PATCH] 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 --- src/flash/nor/tcl.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) 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; -- 2.39.5